Programming Tutorials

(追記) (追記ここまで)

unless in Ruby on rails

By: Brian Marick in Ruby Tutorials on 2008年10月17日 [フレーム]

The word "unless" is in the English language for a reason. Contrast "unless the judge is unfair, you'll win" with "if the judge is not unfair, you'll win." Negations - especially negations of already negative ideas can be confusing. The same is true of Ruby code:

unless unfair(judge)
winner = you
end
if not unfair(judge)
winner = you
end

You can also use unless with the one-line form:

array.pop unless array.empty?



(追記) (追記ここまで)


Add Comment

JavaScript must be enabled for certain features to work
* Required information
1000

Comments

No comments yet. Be the first!
(追記) (追記ここまで)
(追記) (追記ここまで)

AltStyle によって変換されたページ (->オリジナル) /