In ruby there is an option to use case command without a leading variable that is checked in every “when” statement.
The conditions in the case may not be related one to the other.
When the first condition is true all the conditions that weren’t check yet are neglected.
for an example:
class Song
def name
@name
end
def name=(str)
@name = str
end
attr_accessor :Artist
end
song = Song.new
song.name = "Love is love"
song.Artist = "Shlomo Artzi"
case
when song.name == "Love is love"
puts "Me and Eti song !"
when song.Artist == "Boy gorge"
puts "This is the artist form electric dreams"
when Time.now.hour > 23
puts "I should goto sleep"
else
puts "default value is selected "
end
הבלוג שלי מכיל פרסומים של ההתעסקות המקצועית היום יומית שלי שלי בתור ארכיטקט ומוביל טכנולוגיות
יום רביעי, 15 במאי 2013
Ruby case
הירשם ל-
תגובות לפרסום (Atom)
אין תגובות:
הוסף רשומת תגובה