Thursday, May 18, 2023

Ruby Basics

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


Talking to objects

3.even?

Method chains, it will give you 3 as output.

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

Invoking methods with arguments

['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

Friday, May 5, 2023

compare two branches

 git diff <local branch> <remote>/<remote branch>

For example, git diff main origin/main, or git diff featureA origin/next


git diff origin/master  upstream/master


git diff master upstream/master

Ruby Basics

Basics of Ruby   Start Ruby interpret On terminal just type rib ruby_docs $ irb 3 . 0 . 0 : 001 > name = "This is the first ...