Last active
December 24, 2015 01:29
-
-
Save tonussi/6723675 to your computer and use it in GitHub Desktop.
ruby.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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