Ruby Expressions
|
|
|
|
| Articles Reviews Ruby | |||||||||
| Written by Bogdan V | |||||||||
| Sunday, 03 December 2006 | |||||||||
Page 1 of 7
Perhaps less obvious, things that are normally statements in C or Java are expressions in Ruby. For example, the if and case statements both return the value of the last expression executed. songType = if song.mp3Type == MP3::Jazz
In Ruby, many operators are actually method calls. When you write a*b+c you're actually asking the object referenced by a to execute the method ``*'', passing in the parameter b. You then ask the object that results from that calculation to execute ``+'', passing c as a parameter. This is exactly equivalent to writing (a.*(b)).+(c)
class Fixnum
class Song
This code fragment extends class Song with the method ``[]'', which takes two parameters (a start time and an end time). It returns a new song, with the music clipped to the given interval. We could then play the introduction to a song with code such as: aSong[0, 0.15].play
|
|||||||||
| Last Updated ( Sunday, 11 February 2007 ) | |||||||||
| < Prev | Next > |
|---|







