Learning Rails by Example – Chapter 4

hi friends,

Today i started learning 4th chapter of Learning Rails by Example from the book and screencast.

This chapter mainly  covers basics of ruby and we ‘ll learn from Rails console

  • 4.1.2 Cascading Style Sheets
    4.2 Strings and methods
    4.2.2 Strings
  • Printing
  • Single-quoted strings
  • 4.2.3 Objects and message passing
    4.2.4 Method definitions
    4.2.5 Back to the title helper
    4.3 Other data structures
    4.3.1 Arrays and ranges
    4.3.2 Blocks
    4.3.3 Hashes and symbols
    4.3.4 CSS revisited
    4.4 Ruby classes

Simple array:

From “Rails console” terminal

>> (‘a’..’z’).to_a # An alphabet array
=> ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o",
"p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
>> (‘a’..’z’).to_a.shuffle # Shuffle it.
=> ["c", "g", "l", "k", "h", "z", "s", "i", "n", "d", "y", "u", "t", "j", "q",
"b", "r", "o", "f", "e", "w", "v", "m", "a", "x", "p"]
>> (‘a’..’z’).to_a.shuffle[0..7] # Pull out the first eight elements.
=> ["f", "w", "i", "a", "h", "p", "c", "x"]
>> (‘a’..’z’).to_a.shuffle[0..7].join # Join them together to make one string.
=> "mznpybuj"

Simple “do” and “end” function:

>> (1..5).each do |number|
?>   puts 2 * number
>>   puts '--'
>> end
=> 1..5

2 thoughts on “Learning Rails by Example – Chapter 4

  1. Hey Tha.Suresh

    I’m also following the same book for learning rails.
    If you have read the 3rd chapter then,I would like to know what was the result of the final test (Rspec test ).
    coz in my case all the test fails in the end.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s