Skip to content

Instantly share code, notes, and snippets.

@closer
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save closer/9027916 to your computer and use it in GitHub Desktop.

Select an option

Save closer/9027916 to your computer and use it in GitHub Desktop.
Symbol#to_procに引数を指定できるようにしてみる ref: http://qiita.com/closer/items/9e162994583b0c56435d
class Symbol
def to_proc(*args)
-> receiver { receiver.send(self, *args) }
end
alias_method :[], :to_proc
end
puts (0..5).map(&:*[10])
[1, 10, 100].each do |number|
puts "#{number} is"
case number
when :<[5] then puts "less than 5."
when :<[50] then puts "less than 50."
when :<[500] then puts "less than 500."
end
case number
when :>[50] then puts "more than 50."
when :>[5] then puts "more than 5."
when :>[0] then puts "more than 0."
end
end
module Kernel
def less(boundary)
:<[boundary]
end
def more(boundary)
:>[boundary]
end
end
[1, 10, 100].each do |number|
puts "#{number} is"
case number
when less(5) then puts "less than 5."
when less(50) then puts "less than 50."
when less(500) then puts "less than 500."
end
case number
when more(50) then puts "more than 50."
when more(5) then puts "more than 5."
when more(0) then puts "more than 0."
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment