Last active
January 17, 2019 19:31
-
-
Save bchase/db48b784b5156f776e96fd7a7a6993e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Email | |
def self.get_domain(email_address) | |
email_address&.split('@')&.last | |
end | |
end | |
emails = [ '[email protected]' ] | |
p emails.map(&Email.method(:get_domain)) | |
# $ ruby ex.rb | |
# ["these8bits.com"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('[email protected]') ] | |
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