Basics of Ruby
Start Ruby interpret
On terminal just type rib
ruby_docs $ irb 3.0.0 :001 > name = "This is the first string in Ruby" => "This is the first string in Ruby" 3.0.0 :002 > name.length => 32 3.0.0 :003 >
Introduction to Objects
Everything is an object
self
3.even?
1.next.next
if you want to know the all applicable methods on any object just use the methods on the instance like below.
self.methods self.methods.sort "This is string".methods.sort
More Objects and Methods
Looking up methods
1.minutes 1.methods.sort
['rock','paper','scissors'].index('paper')
use the between? method to determine if the number 2 lies between the numbers 1 and 3.
2.between?(1,3)
Syntactic Sugar for Special Methods
Special Methods
4.+(3) 1+2 # this is same as 1.+(2)
words = ["foo", "bar", "baz"] words[1]
above code can be written in below style.
words = ["foo", "bar", "baz"] words.[](1)
page end here