Skip to content

Instantly share code, notes, and snippets.

@bchase
Last active January 17, 2019 19:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bchase/db48b784b5156f776e96fd7a7a6993e0 to your computer and use it in GitHub Desktop.
Save bchase/db48b784b5156f776e96fd7a7a6993e0 to your computer and use it in GitHub Desktop.
module Email
def self.get_domain(email_address)
email_address&.split('@')&.last
end
end
emails = [ 'brad@these8bits.com' ]
p emails.map(&Email.method(:get_domain))
# $ ruby ex.rb
# ["these8bits.com"]
class Proc
# "f after g"
def <<(g)
f = self
Proc.new {|x| f.(g.(x))}
end
end
module Email
def self.get_domain(email_address)
email_address&.split('@')&.last
end
end
User = Struct.new :email
users = [ User.new('brad@these8bits.com') ]
p users.map(&(Email.method(:get_domain).to_proc << :email.to_proc))
# => ["these8bits.com"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment