Last active
August 29, 2015 14:12
-
-
Save meaganewaller/6fbb80b36949a8d1fa6f to your computer and use it in GitHub Desktop.
This file contains 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
one_through_five = *1..5 | |
print one_through_five | |
#=> [1,2,3,4,5] |
This file contains 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
say= *"Hello" | |
print say | |
#=> ["Hello"] |
This file contains 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
def say(message, *people) | |
people.each { |i| puts "#{i}: #{message}"} | |
end | |
people = ["Buffy", "Willow", "Xander"] | |
say("Hi there!", *people) | |
#=> "Buffy: Hi there!" | |
#=> "Willow: Hi there!" | |
#=> "Xander: Hi there!" |
This file contains 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
def add(i,j) | |
i + j | |
end | |
pair = [6,10] | |
add(*pair) | |
#=> 16 |
This file contains 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
names = ["Buffy", "Willow"] | |
more_names = [*names, "Xander", "Angel", "Oz"] | |
print more_names | |
#=> ["Buffy", "Willow", "Xander", "Angel", "Oz"] |
This file contains 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
def say(message, *people) | |
people.each { |i| puts "#{i}: #{message}"} | |
end | |
say("Let's slay some vampires!", "Buffy", "Willow", "Xander") | |
#=> "Buffy: Let's slay some vampires!" | |
#=> "Willow: Let's slay some vampires!" | |
#=> "Xander: Let's slay some vampires!" |
This file contains 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
def say(*messages, *people) | |
people.each do |i| | |
messages.each { |j| puts "#{i}: #{j}"} | |
end | |
end | |
say("Hello", "What's happening?", "Buffy", "Xander") | |
#=> def say(*messsages, *people) | |
# ^ | |
#=> method_definitions_2.rb:5: syntax error, unexpected keyword_end, expecting end-of-input |
This file contains 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
i, j = 50, 75 | |
i, j = j, i | |
puts "#{i}, #{j}" | |
#= >75, 50 |
This file contains 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
names = ["Buffy", "Willow", "Xander", "Angel", "Oz"] | |
first, second = names | |
puts "#{first}, #{second}" | |
#=> "Buffy, Willow" |
This file contains 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
names = ["Buffy", "Willow", "Xander", "Angel", "Oz"] | |
first, *second = names | |
puts "#{first}, #{second}" | |
#=> "Buffy, ["Willow", "Xander", "Angel", "Oz"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment