Skip to content

Instantly share code, notes, and snippets.

@bartoszkopinski
Last active January 3, 2016 14:19
Show Gist options
  • Save bartoszkopinski/8475901 to your computer and use it in GitHub Desktop.
Save bartoszkopinski/8475901 to your computer and use it in GitHub Desktop.
class Symbol
def & s
:"#{self} #{s}"
end
def to_proc
proc do |v|
to_s.split.inject(v){ |val, m| val.send(m) }
end
end
end
[1, nil, 3.0, 'a'].map(&:to_i&:to_s&:to_f)
# => [1.0, 0.0, 3.0, 0.0]
class Symbol
def method_missing s
:"#{self} #{s}"
end
def to_proc
proc do |v|
to_s.split.inject(v){ |val, m| val.send(m) }
end
end
end
[1, nil, 3.0, 'a'].map(&:to_i.to_f.zero?)
# => [false, true, false, true]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment