Ruby Ifelse
Ruby Ifelse operator is a standard conditional operator that allows us to take a certain action based on certain condition.
Ruby IfElse Example
#!/usr/bin/ruby # Filename: ifelse.rb ruby_var = 1 if ruby_var == 2 puts "i am two" else puts "i am one"
Ruby If-ElseIf Example
#!/usr/bin/ruby # Filename: ifelse.rb ruby_var = 1 if ruby_var == 2 puts "i am two" elseif ruby_var == 3 puts "i am three" else puts "i am one"
Conditions in Ruby
Following are the conditions used in Ruby along with their signs:
== equal != not equal to > greater than < less than >= greater than or equal to <= less than or equal to
Ruby String comparison can be learnt for this another section.
Post your Answer