Printing to stdout
puts 'Hello World'
Functions
def functionName ... end def functionName(myvar) puts "Hello #{myvar}!" end
Classes
class Greeter def initialize(name = "World") @name = name end def say_hi puts "Hi #{@name}!" end def say_bye puts "Bye #{@name}, come back soon." end end greeter = Greeter.new("Pat") greeter.say_hi
If/else statements
if @names.nil? puts "..." elsif @names.respond_to?("each") # @names is a list of some kind, iterate! @names.each do |name| puts "Hello #{name}!" end else puts "Hello #{@names}!" end