Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

unless modifier

#!/usr/bin/ruby

$var =  1
print "1 -- Value is set\n" if $var
print "2 -- Value is set\n" unless $var

$var = false
print "3 -- Value is set\n" unless $var

unless statement

#!/usr/bin/ruby

x = 1 
unless x>=2
   puts "x is less than 2"
 else
   puts "x is greater than 2"
end

condition

#!/usr/bin/ruby

$debug = 1
print "debug\n" if $debug

if condition example

#!/usr/bin/ruby

x = 1
if x > 2
   puts "x is greater than 2"
elsif x <= 2 and x!=0
   puts "x is 1"
else
   puts "I can't guess the number"
end

ruby multiline comment

#!/usr/bin/ruby -w

puts "Hello, Ruby!"

=begin
This is a multiline comment and con spwan as many lines as you
like. But =begin and =end should come in the first line only. 
=end

ruby single comment

#!/usr/bin/ruby -w
# This is a single line comment.

puts "Hello, Ruby!"

ruby ranges

#!/usr/bin/ruby

(10..15).each do |n| 
   print n, ' ' 
end

ruby hashes

#!/usr/bin/ruby

hsh = colors = { "red" => 0xf00, "green" => 0x0f0, "blue" => 0x00f }
hsh.each do |key, value|
   print key, " is ", value, "\n"
end

ruby array

#!/usr/bin/ruby

ary = [  "fred", 10, 3.14, "This is a string", "last element", ]
ary.each do |i|
   puts i
end

ruby expression

#!/usr/bin/ruby -w

puts "Multiplication Value : #{24*60*60}";

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.