Skip to content

Instantly share code, notes, and snippets.

@pjb3
Forked from bmuller/symbol_expressions.rb
Created May 25, 2011 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pjb3/990810 to your computer and use it in GitHub Desktop.
Save pjb3/990810 to your computer and use it in GitHub Desktop.
Symbol Expressions Simplified
class Symbol
def |(*args)
@args = args
self
end
def to_proc
Proc.new { |obj|
obj.send *[self] + (@args || [])
}
end
end
class Proc
def self.from_sym(*args)
new { |obj|
args.inject(obj) { |obj, arg| arg.to_proc.call(obj) }
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment