Skip to content

Instantly share code, notes, and snippets.

@tonussi
Last active December 24, 2015 01:29
Show Gist options
  • Save tonussi/6723675 to your computer and use it in GitHub Desktop.
Save tonussi/6723675 to your computer and use it in GitHub Desktop.
ruby.rb
class RubySimples
def simples_acao
puts "Ruby"
end
end
# Output "I love Ruby"
say = "I love Ruby"
puts say
# Output "I *LOVE* RUBY"
say['love'] = "*love*"
puts say.upcase
# Output "I *love* Ruby"
# five times
5.times { puts say }
# The Greeter class
class Greeter
def initialize(name)
@name = name.capitalize
end
def salute
puts "Hello #{@name}!"
end
end
# Ruby knows what you
# mean, even if you
# want to do math on
# an entire Array
cities = %w[ London
Oslo
Paris
Amsterdam
Berlin ]
visited = %w[Berlin Oslo]
puts "I still need " +
"to visit the " +
"following cities:",
cities - visited
# Create a new object
g = Greeter.new("world")
# Output "Hello World!"
g.salute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment