Tuesday, February 18, 2014

Enumerables in Ruby

Using Enumerables in Ruby - Source for the tutorial is Ruby Programming Language
by Yukihiro Matsumoto(creator of Ruby) and David Flanagan.

The blog below has a sample code with output. The sample code below with inline comments in a way summarizes the concept(refer blog title) covered as part of the book.

#Playing with Enumerable Objects
squares = [1,2,3].collect { |x| x*x }
print("Squares:")
puts(squares)
puts("\n")
#--------------------------------------------------------------------------------------------------------------------------------
print("Odd numbers upto range:\n")
odds = (1..25).select { |x| x%2 != 0 }
puts(odds)
puts("\n")
#--------------------------------------------------------------------------------------------------------------------------------
print("Even numbers upto range:\n")
evens = (1..25).reject { |x| x%2 != 0 }
puts(evens)
puts("\n")
view raw enumerables.rb hosted with ❤ by GitHub
Squares:1
4
9
Odd numbers upto range:
1
3
5
7
9
11
13
15
17
19
21
23
25
Even numbers upto range:
2
4
6
8
10
12
14
16
18
20
22
24


Loops in Ruby

Using Loops in Ruby - Source for the tutorial is Ruby Programming Language by Yukihiro Matsumoto(creator of Ruby) and David Flanagan.

The blog below has a sample code with output. The sample code below with inline comments in a way summarizes the concept(refer blog title) covered as part of the book.

# loops in Ruby
# While
x = 10
while x >= 0 do
puts x
x = x - 1
end
#--------------------------------------------------------------------------------------------------------------------------------
puts("\n")
# Until
x = 0
until x > 10 do
puts x
x = x + 1
end
#--------------------------------------------------------------------------------------------------------------------------------
puts("\n")
# While as a modifier
x = 5
puts x = x + 1 while x < 10
#--------------------------------------------------------------------------------------------------------------------------------
puts("\n")
# Until as a modifier
a = [1,2,3]
puts a.pop until a.empty? # behaves like a stack.. the op is in LIFO manner
#--------------------------------------------------------------------------------------------------------------------------------
#for loop implementation..
puts("\n")
array = [ 1, 2, 3, 4, 5 ]
for element in array # note the use of built in keywords like element simplifies our usage..
puts element # making ruby more simpler to use
end
puts("\n")
hash = { :a => 1, :b => 2, :c => 3 } # here key and value are built in keywords wrt hashes in Ruby..
for key,value in hash
puts "#{key} => #{value}"
end
#--------------------------------------------------------------------------------------------------------------------------------
view raw loops.rb hosted with ❤ by GitHub
10
9
8
7
6
5
4
3
2
1
0
0
1
2
3
4
5
6
7
8
9
10
6
7
8
9
10
3
2
1
1
2
3
4
5
a => 1
b => 2
c => 3
view raw loops_output hosted with ❤ by GitHub


Iterators in ruby

Using Iterators in Ruby - Source for the tutorial is Ruby Programming Language by Yukihiro Matsumoto(creator of Ruby) and David Flanagan.

The blog below has a sample code with output. The sample code below with inline comments in a way summarizes the concept(refer blog title) covered as part of the book.

# working with iterators
3.times { puts "thank you!" }
puts("\n")
data = [1,2,3,4,5]
data.each {|x| puts x} # note how x although its not being declared or defined.. works for each element of the array data..
puts("\n")
[1,2,3,4,5].map { |x| puts x*x }
# see the beauty of iterators in Ruby in terms of how the factorial is implemented...
print("Enter the number whose factorial you want to find out: ")
n = gets.to_i
$factorial = 1
2.upto(n) { |x| $factorial *= x }
puts("Factorial of #{n} is:- #{$factorial} ")
view raw iterators.rb hosted with ❤ by GitHub
thank you!
thank you!
thank you!
1
2
3
4
5
1
4
9
16
25
Enter the number whose factorial you want to find out: 4
Factorial of 4 is:- 24


Conditionals in Ruby

Using Conditionals in Ruby - Part 1 - Source for the tutorial is Ruby Programming Language by Yukihiro Matsumoto(creator of Ruby) and David Flanagan.

The blog below has a sample code with output. The sample code below with inline comments in a way summarizes the concept(refer blog title) covered as part of the book.

# Conditionals
a = 5
b = 3
# if else in operation..
if a < b
puts("true")
else
puts("false")
end
# if elsif else in operation..
if a < b
puts("a is less than b")
elsif a == b
puts("a is equal to b")
else
puts("a is greater than b")
end
# return value
x = 2
month = if x == 1 then "january"
elsif x == 2 then "february"
elsif x == 3 then "march"
elsif x == 4 then "april"
else "The Month is not either of the above four months"
end
puts(month)
# a different Avatar of if.. Ruby making things simpler..
puts x if x # if x is defined it will print the value of x.. do note..
#--------------------------------------------------------------------------------------------------------------------------------
# unless
unless a == 3 # this condition is false or nil.. the actual value of a is 5.. this condition works as the opposite of the if condition..
puts(" value of a is not 3 ")
end
# unless with else
unless x == 0
puts "x is not 0"
else
unless y == 0
puts "y is not 0"
else
unless z == 0
puts "z is not 0"
else
puts " all are zero "
end
end
end
#--------------------------------------------------------------------------------------------------------------------------------
# case
name = case
when x == 1 then "one"
when 2 == x then "two"
when x == 3 then "three"
when x == 4 then "four"
when x == 5 then "five"
else "nothing among the first five"
end
puts(name)
#--------------------------------------------------------------------------------------------------------------------------------
view raw conditionals.rb hosted with ❤ by GitHub
false
a is greater than b
february
2
value of a is not 3
x is not 0
two


Operators in Ruby - Part 2

Using Operators in Ruby - Part 2 - Source for the tutorial is Ruby Programming Language
by Yukihiro Matsumoto(creator of Ruby) and David Flanagan.

The blog below has a sample code with output. The sample code below with inline comments in a way summarizes the concept(refer blog title) covered as part of the book.

false
true
false
4
0
3
0
false
true
true
7
4
5
6
7
7
You have 2 messages
6
9
7
view raw op2_output hosted with ❤ by GitHub
# Equality operators( '==' and check this '==='( case equality operator.. do note.. ) ).
a1 = 3
a2 = 4
a3 = 0
s1 = (a1==a2)
puts(s1)
s2 = (a3!=a2)
puts(s2)
z1 = [ 4..10 ]
puts((1..10) == 5)
#--------------------------------------------------------------------------------------------------------------------------------
#Boolean operators( &&, ||, ! ), new things to learn here.. do note..
b1 = a3 && a2 # NOTE THIS!! here what happens is that the boolean && in Ruby works differently.. if the 1st operand is neither nil or false..
puts(b1) # the value of the second operand is printed as the output.. Advtg of using this is its like a short-circuit operator..
b2 = a3 & a1 #this is the logical AND.. do note the difference..
puts(b2) # Advtg of using this is.. its like a short-circuit operator..
b3 = a1 || a2 # note this too.. here.. if the 1st operand is neither a nil or false the op is the 1st operand.. else its second operand..
puts(b3)
b4 = 0 | a3 #this is the logical OR .. do note the difference..
puts(b4)
b5 = !a3 # NOTE THIS!! in Ruby 0 is not equivalent to nil or false.. as you would otherwise find in C Programming.. hence the op
puts(b5)
b6 = !nil
puts(b6)
b7 = !false
puts(b7)
#--------------------------------------------------------------------------------------------------------------------------------
#cool..check this out..!! + conditional operator.. + defined?
c = 4
c += 3
puts(c)
c1,c2,c3 = 4,5,6
puts(c1)
puts(c2)
puts(c3)
c4=c5=7
puts(c4)
puts(c5)
n = 2
puts("You have #{n} #{n==1 ? 'message' : 'messages'}")
c3>c5 ? c3=9 : c5=9 # do note if its given the way below.. there is an error.. probably as it would tkae :c5 as a symbol n not a part of the conditional op.
#c3>c5?c3=9:c5=9
puts(c3)
puts(c5)
s1 = c if defined? c # if variable is defined copy its value to s1..
puts(s1)
#--------------------------------------------------------------------------------------------------------------------------------
view raw Operators2.rb hosted with ❤ by GitHub


Operators in Ruby - Part 1

Using Operators in Ruby - Part 1 - Source for the tutorial is Ruby Programming Language by Yukihiro Matsumoto(creator of Ruby) and David Flanagan.

The blog below has a sample code with output. The sample code below with inline comments in a way summarizes the concept(refer blog title) covered as part of the book.

true
16
24 -16 80 5 0
22
22
2
2
hello world
hello world
1
0
-1
-12
1
value of a1 is: 24 and value of a2 is: -16
false
true
false
true
1
view raw op1_output hosted with ❤ by GitHub
# Playing with operators in Ruby
limit = 5
p = 2 * Math.sqrt(4) < limit
puts(p)
k = 2 ** 4 # Exponentiation Operator..
puts(k)
#--------------------------------------------------------------------------------------------------------------------------------
t = 4
l = 20
a1 = t + l
a2 = t - l
a3 = t * l
a4 = l / t
a5 = 20 % 4
puts("\n#{a1}\t#{a2}\t#{a3}\t#{a4}\t#{a5}\n")
#--------------------------------------------------------------------------------------------------------------------------------
# Left and Right Shift operators..
b1 = 11 << 1
b2 = 11 >> -1 # !! check the working of this..
puts(b1)
puts(b2)
b3 = 22 >> 3
b4 = 22 << -3 # !! check the working of this..
puts(b3)
puts(b4)
#--------------------------------------------------------------------------------------------------------------------------------
# Right Shift operator also used for appending..also use of STDOUT Predefined Global constant..
message = "hello"
messages = []
message << " world"
puts(message)
STDOUT << message
print("\n")
#--------------------------------------------------------------------------------------------------------------------------------
# working of AND, OR, Tilde(~) and XOR
c1 = 0 | 1
puts(c1)
c2 = 0 & 1
puts(c2)
c3 = ~0 # ~ for a variable x it functions as -x-1.. here its -0-1 thus op is c3 = -1
puts(c3) # this is the way of functioning for an INTEGER...
c4 = ~0b1011 # 11 in binary is .. 1011.. '~' converts all 0's to one and vice versa..
puts(c4) # Thus we get.. 0100.. thats 4.. DOUBT... DO NOTE..?????????????????????????
c5 = 1 ^ 0
puts(c5)
#--------------------------------------------------------------------------------------------------------------------------------
# working of comparison operators
print("\nvalue of a1 is: #{a1} and value of a2 is: #{a2}\n")
s1 = a1<a2
puts(s1)
s2 = a1>a2
puts(s2)
s3 = a1<=a2
puts(s3)
s4 = a1>=a2
puts(s4)
s5 = a1<=>a2 # note the working of the comparison operator of Ruby it prints the value of 1 if a1>a2, 0 if both r equal and -1 if a1<a2
puts(s5) # the idea behind this operator is that it a multipurpose general operator.. hence.. used in classes.. it provides convenience..
#--------------------------------------------------------------------------------------------------------------------------------
view raw Operators1.rb hosted with ❤ by GitHub


User input in Ruby

This is a sample program which takes user input and prints the same in Ruby

HI..!! enter ur name please: Test User
Hello Test User
view raw output hosted with ❤ by GitHub
print('HI..!! enter ur name please: ')
name = gets()
puts("Hello #{name}")
#this symbol is mainly used for comments.. what role is it playing here..??
# the hash symbol in the puts stmnt above within quotes can be used to print the value of the entity within the quotes
puts("\n")
#<<name


Arrays in Ruby

Using Arrays in Ruby - Source for the tutorial is Ruby Programming Language
by Yukihiro Matsumoto(creator of Ruby) and David Flanagan.

The blog below has a sample code with output. The sample code below with inline comments in a way summarizes the concept(refer blog title) covered as part of the book.

1
6
Using size(above) n length(below) properties to print no. of elements in a string
6
tryin to print anything outside array bounds ..like value of a[8] prints nill.. do note..
11
note how through a[-3] we get the value of the third last element of the array 7
changing value of 1st element of array to 25.. and printing it.. note the way its printed..25
Dyanmically do note how the size of an array can be increased in Ruby..Making things simpler n Faster..and a programmer can't be happier.. Yukihiro Matsumto
value of a[6]: zero
Also note how ruby is allowing the programmer to have an array with diverse data types...
to print the elements within the range of a[9]26
27
28
29
30
to print the first two elements of an array
25
3
Values of array before change within a specified range..:
[3, 5, 7, 9, 11, "zero", nil, nil, [26, 27, 28, 29, 30]]
changing values of an array within a specified range
[5, "Yapdi", "Irika", 11]
Note the difference between the above op and the op below due to the diff of just one '.' in the range 2 to 5
[5, "Yapdi", "Irika"]
true
true
true
does the array of r include the symbol l?: false
a[7] is nil? ans: true
view raw Arrays hosted with ❤ by GitHub
# working wit arrays - covering basic examples .. not all..
#--------------------------------------------------------------------------------------------------------------------------------
a = [ 1,3,5,7,9,11 ]
puts(a[0]) # prints the 1st element value of the array...
#--------------------------------------------------------------------------------------------------------------------------------
print( a.size ) # prints the length of the array...
puts("\nUsing size(above) n length(below) properties to print no. of elements in a string\n")
print( a.length )
#--------------------------------------------------------------------------------------------------------------------------------
print(a[8]) # doesn't work..but the below will work..
#--------------------------------------------------------------------------------------------------------------------------------
print("\ntryin to print anything outside array bounds ..like value of a[8] prints nill.. do note.. ")
puts(a[8])
puts(a[-1])
#--------------------------------------------------------------------------------------------------------------------------------
print(" note how through a[-3] we get the value of the third last element of the array ")
puts(a[-3])
#--------------------------------------------------------------------------------------------------------------------------------
print("changing value of 1st element of array to 25.. and printing it.. note the way its printed..")
a[0] = 25
puts(a[-a.size])
#--------------------------------------------------------------------------------------------------------------------------------
print("Dyanmically do note how the size of an array can be increased in Ruby..Making things simpler n Faster..\
and a programmer can't be happier.. Yukihiro Matsumto\n")
a[6] = "zero"
puts("value of a[6]:\t #{a[6]} ")
print("Also note how ruby is allowing the programmer to have an array with diverse data types... \n")
#--------------------------------------------------------------------------------------------------------------------------------
a[9] = (26..30).to_a
print("\nto print the elements within the range of a[9]")
puts(a[9,])
#--------------------------------------------------------------------------------------------------------------------------------
print("\nto print the first two elements of an array\n")
puts(a[0..1])
#--------------------------------------------------------------------------------------------------------------------------------
#how to print array elements within a[9] .. upto a specific range..??
#print("to print the elements within the range of a[9]")
#puts(a[9,[1,2]])
#???????
#--------------------------------------------------------------------------------------------------------------------------------
puts("\n Values of array before change within a specified range..: \n #{a[1..9]} ")
print("\nchanging values of an array within a specified range")
a[3..4] = ['Yapdi','Irika']
#--------------------------------------------------------------------------------------------------------------------------------
puts("\n #{a[2..5]} ")
print("\n Note the difference between the above op and the op below due to the diff of just one '.' in the range 2 to 5 \n")
puts("\n #{a[2...5]} ")
#--------------------------------------------------------------------------------------------------------------------------------
# now dealing mainly with ranges, true, false and nil..
r = 'a'..'c'
puts(r.include? 'a')
puts(r.member? 'b') #member and include are like synonyms.. do note..
puts(r.cover? 'c') # even the cover works the same.. as member n include..
print("does the array of r include the symbol l?: ")
puts(r.include? 'l')
print("\na[7] is nil? ans: ")
puts(a[7].nil?)
#--------------------------------------------------------------------------------------------------------------------------------


Playing with Numbers in Ruby

Using Numbers in Ruby - Source for the tutorial is Ruby Programming Language
by Yukihiro Matsumoto(creator of Ruby) and David Flanagan.

The blog below has a sample code with output. The sample code below with inline comments in a way summarizes the concept(refer blog title) covered as part of the book.

20
6
50
Subtraction of 50 - 30 is: 20
Exponentiation of 3^3 is: 27
Value of 5 modulo 3 is: 2
view raw numbers in ruby hosted with ❤ by GitHub
# playing with numbers.. Checking the general backslashes to be run..
puts( 4 * 5)
puts("\n")
# This is not allowed..I guess.. puts (100/20) puts("\t") puts(20 + 30)
puts (100/20 + 90/54)
puts("\t")
puts(20 + 30)
# Escape sequences and all need to be given with double quotes not single quotes.. puts("\n")
puts("\n")
num = 50 - 30
puts("Subtraction of 50 - 30 is: \t #{num}")
num1 = 3**3
puts("Exponentiation of 3^3 is: \t #{num1}")
num2 = 5%3 # Modulo in operation.. do note..
puts("Value of 5 modulo 3 is: \t #{num2}")


Helloworld in Ruby

Hello world program in Ruby

Hello World
puts("Hello World")
view raw Helloworld.rb hosted with ❤ by GitHub


Using Hashes in Ruby

Using Hashes in Ruby - Source for the tutorial is Ruby Programming Language
by Yukihiro Matsumoto(creator of Ruby) and David Flanagan.

The blog below has a sample code with output. The sample code below with inline comments in a way summarizes the concept(refer blog title) covered as part of the book.

Total Months via hashes: 8
#{numbers["two"]}
zero
5
view raw Hashes hosted with ❤ by GitHub
#Playin with Hashes..:)
#--------------------------------------------------------------------------------------------------------------------------------
months = Hash.new
months["january"] = 1
months["july"] = 7
total_months = months["january"] + months["july"]
puts("Total Months via hashes: #{total_months} ")
puts "#{months["june"]}"
#note how a value of null is assigned to a hash of months .. as it was defined with no default initial value
#--------------------------------------------------------------------------------------------------------------------------------
#also check how puts is working without the use of parentheses..
numbers = Hash.new{"zero"}
puts '#{numbers["two"]}' # givin it this way won't work.. need to use double quotes...
puts "#{numbers["two"]}"
#--------------------------------------------------------------------------------------------------------------------------------
# usage of hash literals... as key value pairs.. Here we are using symbols.. but even quotes can be used.. as shown above..
week = Hash.new
week = { :sunday => 1, :monday => 2, :"tuesday" => 3, :wednesday => 4, :thursday => 5, :'fri day' => 6, :saturday => 7 }
puts "#{week[:thursday]}"


Saturday, February 8, 2014

One plus One is eleven - Individual Ubuntu dev boxes vs Single Redhat dev server for a team of developers

Hi,

Below are certain points(based on my experience till date) on the basis which I've tried to put forth my two cents on the pros and cons of having an individual development setup(for each developer)(using Ubuntu) v/s using a single development box(in this case it is Red Hat Enterprise Linux OS on which each developer would have individual user account through which they would go about day to day development - this is a sample case study with no direct/indirect reference to any individual/organization) for a team of multiple developers who would be working on a Ruby on Rails application.

Also, I would like to clarify why this comparison is done is because we are assuming a hypothetical scenario where the production app server is deployed on RedHat OS and the debate is about having the right development server in place for day to day development - keeping in mind the specific goal on how can one achieve more(be more productive and kinda spend not more time than what's ideally reqd for day to day development) with less(for e.g., simply by being smart when one has to be and finding the shortest path - reminds me of Dijkstra's algorithm ;) )

An attempt to list down the differences one by one follows below -



SE NO
Point of discussion
Ubuntu
Non Ubuntu - RedHat
1
Development setup
Individual for each developer
Common for all developers(one server, multiple user accounts)
2
Internet required for development
No
Yes(because we connect via putty installed on Windows to dev server).
From Home – via some VPN
From Office – Office intranet
3
Chances of intermittent connection loss to dev server when moving laptop from one place to another say to attend meetings etc.,
No concept of connection being effected as internet not used for day to day development(Your development box is your local box – Cheers J )
0 – 15 %(approx.)
Impact – Need to again reconnect to the server and open multiple putty sessions again(this mean logging into each individual session multiple times).
1.       For starting the server
2.       For tracing the log
3.       Opening the rails console
4.       (optional) for accessing the mysql console
4
Need to commit to see if your code changes work properly on the application
No
Yes and No.
Yes in the case where -1. You are working from your local desktop
 2. You’re using an editor like Sublime Text
 3. Committing those changes via something like Tortoise SVN(an interface to ease you SVN committing process)
4. Doing an update from the server side to fetch latest code and only then checking if your changes work properly or not.
This approach is not recommended because the general rule of thumb to committing code is that you make changes, test them.. If all things work fine only then go about committing the same.

No in the case where
1 Directly code via putty
2. Don’t have an editor
3. Overhead of not having the editor –
a. copying the code is a challenge if same/similar functionality has to be used in different files within the same application
b. Copying the code from one place to other spoils the alignment and the entire copied code needs to be realigned(as a result development becomes more time consuming).

It's kinda everyone's wish to get the best of both world's isn't it :). There's a way through Samba by which you can actually map your local boxes network drive to point to one of the remote servers(provided you have access to the same) and you can specifically point it to the codebase on which you're currently working. Through this service your changes made using the editor which basically opens the code on the remote server will automatically reflect in the remote server. Sound's good isn't it :). Well yeah, I've heard sometimes people use Samba as means to deep dive into their application logs(for debugging etc.,). Hmm, but having this for day to day development would be an icing on the cake, isn't it :). The prerequisite for it to be allowed for day to day development might be that you need to have support for Samba(not sure about it in detail just sharing knowledge based on what I know or have come across till date).Things can actually get more challenging as mentioned above if you don't have Samba support.
This seems to take care of this point, but what about others... read on before you reach to any conclusion ;).

5
Do we have an independent platform where a developer is empowered to showcase Proof of Concepts(POC’s)?
Yes
No(because we are all using a shared server – we need to be very cautious when we experiment with things).
6
Will your application break if you develop in Ubuntu and deploy(for prod) on Redhat
It depends(can’t be taken for granted it will or it won’t). A best way to answer this is to see if equivalent packages/plugins that are used as part of the application are available for Ubuntu and Windows. Bottom line, if this breaks for one application it can’t be taken for granted it will break on all applications. Root cause analysis needs to be done to go into exact details and decisions need to be made based on the same.
7
Freedom of a developer to have his/her playground to demonstrate his potential
Can do more. Every user will have his/her own root access to install additional softwares which can be used for the benefit of the company. Sometimes when you want to install app specific packages also, it’s easier to do it without any approval process in the loop(provided you are confident of what you are DOING)

It’s more of show me the code first before you talk.(taken from the saying – “talk is cheap, show me the code” – mentioned by Linus Trovalds the creator of the Linux Kernel)
Can do very less – needs to take approval for every single installation as this server is used by multiple people. What happens in the bargain ? – More time consuming for a developer to show his/her potential. Every developer will not have the root credentials only sys admin will have it(in some cases it’s the linux support team).
8
Cost
Free – Open Source. Can development be cheaper J ?
Huge cost involved for every developer to have the individual Red Hat development Setup.
9
Support
Independent. Not required, as it’s an individual desktop. If one breaks only a developer is impacted not the entire team. To fix any issues we have Ubuntu forums like – AskUbuntu, UbuntuForum, Ubuntu Mailing List, IRC
Dependent on Linux support teams within the corporate organization(if such a team exists) or on the Red Hat support staff from whom we’ve originally bought the OS.
10
Security
Shouldn’t be a concern as we will be using Ubuntu VM’s on Windows platforms. There should already be company firewalls protecting our internal systems through firewalls etc., IMHO.
Already taken care in a way by the support from Red Hat, Linux support team within the company(if exists) + support from firewalls setup with respect to the company network.
11
Single Point of Failure
No. One machine goes down. Use the VDI and clone the setup. We can keep a master copy of the setup and distribute it among all team members. Any changes to the application should be reflected in one of the master setups(which nobody plays around with). Thereby if  one developer ends breaking things, he doesn’t have to do much to get back the latest setup reqd for the application to be up and running. Only he will have to rework his local changes(say wrt the POC’s which will be in WIP)
Yes. One machines goes berserk, several developers are impacted(that’s why nobody wants to take risks and sometimes you lose out in the competition just because we don’t take calculated risks to speed up things).


These are my own personal views and I'm open to any pointers in case I'm missing something with respect to the differences mentioned above or if you'd like to add more differences the ones already mentioned above.

I'd be happy to pass on the mantle to all readers who would like to discuss more on this topic through comments on this post. It's your playground from here, take it away :) .

Net-Net - I think the differences talk for themselves and IMHO one should be in a position to independently take a call on what works best for them as some things could vary on a case to case basis.

Cheers :)

P.S:- One plus + One equals eleven is a pun that I've used for two individual entities being combined together to give you a single result.. One of the entities is Windows and I leave it to you to figure out what the other entity stands for .. :);)


Debugging your Rails apps - how I go about it generally

Hi,

To debug your Rails apps the following cmds are what I generally use.

a. Rails.logger.info . They are many variants to using this based on different scenarios. One of them is -
1. To just get a better hang of the flow of how the call passes goes from one place to another-

Rails.logger.info " Your Message goes here"

An easy way of finding the same in your log could be

Case 1

Rails.logger.info "\n*********\n Your message goes here\n********\n"

2. To get the flow and also to see the values used/passed anywhere in the method(s) called as part of your action which triggered the functionality

Say if 

Case 2

a = "hi"
Rails.logger.info "\n*********\n Your message goes here - #{a}\n********\n"

The above statement will print your message with the value of a.

3. Another very useful thing that I use from time to time is making use of the 'inspect' option. With experience I can definitely say it's very helpful when you for e.g., want to see what all are passed as part of a click of a submit button, the entire list of params that are passed(with the exact format like for e.g., say your passing a hash with multiple key value pairs) or basically the object values can be clearly seen and printed via the Rails Logger.

Sample e.g.,

Case 3

Rails.logger.info "\n*********\n Your message goes here - #{a.inspect}\n********\n"

Hope you find them useful. In case you have better suggestions on can one better debug, please feel free to share your suggestions as comments to this post.

You can read more about how to better debug your Rails apps from the Rails Guides (I've taken a reference from Rails 2.3 guides just as an e.g.,).

Thank you.