RUBY

What is Ruby?

  • dynamic
  • elegant
  • object oriented

Install

  • home brew
  • rvm
  • rbenv(with ruby-build)

REPL

  • IRB
  • PRY

Type

  • Number
  • String
  • Symbol
num = 3
3.odd?
3.even?
3.next

str = "abc"
str.length

someValue = nil
someValue.nil?

aaa = "abc"
bbb = "abc"

aaa == bbb //
aaa.equal? bbb //

sym1 = :abc
sym2 = :abc

sym1.equal? sym2

num3 = 1_000_000

Expression

  • everything
flag = true
name = if flag
          "joe"
       else
          "other"
       end


def some_method
  "bla"
end

container

  • Range
  • Array
  • Hash
tmp = (1..10)


name_hash = { :name => 'joe' }
puts name_hash[:name]

name_hash2 = { name: "joe" }

arr = ["aa", "bb", "cc"]
arr2 = %w(aa bb cc)


arr = 1..10
arr.each { |item| puts item }

arr.map do |item|
  item * item
end

arr.map(&:to_s)

RUBY

By odyss

RUBY

  • 2,266