=begin This file is simply the “tangled” Ruby code of ruby-f#-demo.org; it is the “raw” source code, provided for your convenience. =end x = 10 y = 5 puts x puts y puts x < y puts x > y puts x == y x = 10 y = 5 Kernel.puts(x) Kernel.puts(y) Kernel.puts(x.< y) Kernel.puts(x.> y) Kernel.puts(x.== y) x = 10 y = 5 Kernel.send "puts", x Kernel.send "puts", y Kernel.send "puts", (x.send "<", y) Kernel.send "puts", (x.send ">", y) Kernel.send "puts", (x.send "==", y) x = 10000 if x > 1000 then puts "x is impossibly large!" end x = 10000 if x > 1000 then puts "x is impossibly large!" end if x < 100000; puts "But it's not all that impossibly large..." end x = 10000 puts "x is impossibly large!" if x > 1000 puts "But it's not all that impossibly large..." if x < 100000 has_if = true has_elsif = true has_else = true if false then puts "Whoa, you're in trouble." else if has_elsif then puts "Why didn't you use 'elsif' instead of 'else if' then?" elsif has_if and has_elsif then puts "Ah, I guess you had no choice then." end end lacks_unless = false puts "No need for 'if not ...'!" unless lacks_unless x = 0 while x <= 5 do puts "Counting up with while..." ++ x.to_s x += 1 end until x == 0 do x -= 1 puts "Counting down with until..." ++ x.to_s end for x in 1..5 do puts "Counting up with for..." ++ x.to_s end 5.times do |x| puts "Repeating a task with times..." ++ x.to_s end [1,2,3,4,5].each do |x| puts "Iterating over a list with each..." ++ x.to_s end f = lambda { |x, y| puts "Hey, how'd you call me? I'm not supposed to have a name!" puts "Well, anyway, take your stuff back." puts x puts y } g = f f.("f's","stuff") puts "" g.call "g's", "things" puts "Hello world" puts "It's nice to meet you" print "Whatever you do, " print "don't squish these lines together!" gets=78 puts "Guess my favourite number." guess = gets puts "How'd you know it was #{guess}?" will = "will" will_not = "will not" puts "I #{will} be formatted." puts 'I #{will_not} be formatted.' puts "I %s also be formatted. Maybe you like my syntax more." % [will]