Learning Ruby – for buildr

I decided to learn ruby for using buildr as my build system for the diploma thesis. So, I looked for a book your guide to learn it. And I found an excellent and funny one which represents the syntax, semantic and much more of ruby.

It can be downloaded here: http://www.scribd.com/doc/8545174/Whys-Poignant-Guide-to-Ruby

I now summarize the key features of ruby to be able to read and understand ruby as fast as possible:

  • name or name_asd or name1_a_1 is variable
  • Name is a constant (as its The Empire State Building)
  • $varname is a global variable (everybody behaves the same way if you give him a $)
  • @varname is an instance variable  (speak: attribute)
  • @@varname is a class variable (speak: attribute for all)
  • :name is a symbol
  • { print “test” } is a block as it is do print “test” end
  • { |x,y| x + y } where x,y is a block argument representing input parameters of the block
  • (1..5) or (‘a’ .. ‘z’) are ranges, like an accordeon (a third dot includes the last element, too)
  • [1, 2, 3] is an array
  • {‘xml’ => ‘eXtensible Markup Language’, ‘sql’ => ‘Structured Query Language’} is a dictionary
  • /regex/ contains a regular expression
  • nil represents emptyness
  • << is the concatenation operator, which is a method
  • puts print something on console
  • gets reads from user input
  • def is used to define methods
  • case is used with when to switch over the characteristics of a variable
  • initialize is the default constructor
  • < means inheritance or extends from the java perspektive
  • class classname creates a class and has to be ended using the keyword end
  • wrap code together using modules
  • attr_accessor :picks, :purchased is a shortcut for creating getter and setter for the variables picks and purchased
    attr_reader :picks, :purchased is used for creating only getters

I thinks, this should now suffice to work with buildr. I will update this while I dig through buildr to automate my transformation process.

Advertisements

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