Skip to content

Instantly share code, notes, and snippets.

@rafer
rafer / question_17.rb
Created April 14, 2011 20:40
ROB 4/14/2011 Trivia: Question 17
# Question 17. What does the following print?
p 10.step(100, 20).to_a
@rafer
rafer / question_16.rb
Created April 14, 2011 20:39
ROB 4/14/2011 Trivia: Question 16
# Question 16. What does the following print?
enum = ("branch"..."orbital socket").to_enum
p enum.next
p enum.next
p enum.next
@rafer
rafer / question_15.rb
Created April 14, 2011 20:38
ROB 4/14/2011 Trivia: Question 15
# Question 15. What are the values of a, b, c and d?
a, (b, *c), d = 1, [2, 3, 4], 5
@rafer
rafer / question_14.rb
Created April 14, 2011 20:37
ROB 4/14/2011 Trivia: Question 14
# Question 14. What are the values of a, b, c and d?
a, (b, c), d = 1, 2, 3, 4
@rafer
rafer / gist:920466
Created April 14, 2011 20:36
ROB 4/14/2011 Trivia: Question 13
# Question 13. What are the values of a and b?
*a, b = [1, 2, 3, 4]
@rafer
rafer / gist:920464
Created April 14, 2011 20:35
ROB 4/14/2011 Trivia: Question 12
# Question 12. What does the following print (as of Ruby 1.9)?
thang = "biscuits"
[1,2,3].each { |n; thang| thang = n }
puts thang
@rafer
rafer / gist:920460
Created April 14, 2011 20:34
ROB 4/14/2011 Trivia: Question 11
# 11. What does the following evaluate to (as of Ruby 1.9)?
__method__
@rafer
rafer / gist:920458
Created April 14, 2011 20:34
ROB 4/14/2011 Trivia: Question 10
# 10. What does the following evaluate to?
__FILE__
@rafer
rafer / gist:920447
Created April 14, 2011 20:31
ROB 4/14/2011 Trivia: Question 9
# Question 9. What does the "def" look like for prefixed unary operators as in:
trinsty = Crowndis.new
negative_trinsty = - trinsty
@rafer
rafer / gist:920441
Created April 14, 2011 20:29
ROB 4/14/2011 Trivia: Question 8
#8. What instance method is defined on Symbol in active_support/ruby 1.9.2 to enable the ampersand trick?
# For example:
[1].map(&:to_s) # => ["1"]