Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

5 Commits

Repository files navigation

Simplified Ruby

What is it?

Simplified Ruby is a minimal subset of the Ruby syntax that allows to take any problem description and turn it into idiomatic, easy to understand and boring Ruby code.

Motivation

Ruby has a lot of features, quirks, and ways to solve the same problem. I believe that you can take 20% of its syntax and still be able to write code that does the job. This is especially true when you're using a framework (like Ruby on Rails) and a lot of technical problems are being handled for you.

Limiting yourself to Simplified Ruby shifts the focus from technical problems (exciting, but your company probably won't earn money for solving them) to business domain problems (here's your real leverage). You end up with code that is easy to read, easy to understand for your colleagues regardless of their seniority, and easy to delete.

This project can also be useful:

  • when introducing people to programming
  • to answer the question "how much Ruby syntax do I need to start writing Ruby on Rails applications?"
  • during technical interviews for introductory Ruby positions
  • for company career ladder to define "basic Ruby knowledge"

Syntax

simple types - String, Symbol, Fixnum, Float, nil, booleans

"adam":adam563.4niltruefalse

method call - .

"adam".upcase

arthimetical operators - +, -, *, /, **, %

2 + 5.423 - 1010 * 29 / 22 ** 38 % 3

string interpolation

"this is #{4}."

comparison operators

2 + 2 == 43 != 4

logical operators - &&, ||, !

"adam".length.zero? && 2 + 2 == 4"adam".length.zero? || 2 + 2 == 4
!"adam".length.zero?

conditional statements - if / elsif / else

if"adam".length.zero?"awesome"elsif2 + 2 == 43else"something else"end"test"if2 + 2 == 4

container types - Array, Hash

[1,2,3]{"age"=>3}

short-hand notation for Hash with symbol keys

{age: 3}

local variables

name="adam"

assignment operator

age=2 + 3age="five"

defining methods

defmy_method(argument)"I got #{argument}"end

return

defmy_method(argument)return"a"ifargument.zero?"bbb"end

keyword arguments

defmy_method(argument,name:,age: 18,city: nil)end

comments

# this is how it works

blocks

[1,2].mapdo |element|
element * 2end

defining a class

classUserend

new

user=User.new("adam")

instance method

classUserdefname"adam"endend

instance variable

classUserdefgive_name(name)@name=nameenddefname@nameendend

initialize

classUserdefinitialize(name)@name=nameendend

private

classUserdefintroduce"I am #{age}"endprivatedefage4endend

self

classUserdefcarCar.new(self)endend

class method

classUserdefself.give_me_three[User.new,User.new,User.new]endend

constant inside a class

classUserCODE_LENGTH=3defcode(name)name.slice(0,CODE_LENGTH)endend

inheritance - <

classUserdefroles[]endendclassSupervisor < Userdefroles["admin","supervisor"]endend

super

classSupervisor < Userdefcode(name)"#{super("ADMIN")}#{super}"endend

nested classes

classUsersclassAdminendendUsers::Admin.new

attr_reader, attr_writer, attr_accessor

classUserattr_reader:nameattr_writer:agoattr_accessor:cityend

||=

classUserdefgive_name(name)@name ||= nameendend

begin / rescue / raise

begin2 + 2raise"error"4 * 7rescue=>ex"Aaaa #{ex}!!!"end

Basic methods

About

Simplified Ruby is a minimal subset of the Ruby syntax that allows to take any problem description and turn it into idiomatic, easy to understand and boring Ruby code.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors