Created
September 16, 2016 12:08
-
-
Save Irostovsky/1b5b3a071dced1d8070256b0bd41de4e 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
class Developer | |
def initialize | |
@chain = [] | |
end | |
def are | |
@chain << "I" | |
self | |
end | |
def crazy | |
@chain << 'am crazy' | |
self | |
end | |
def and &block | |
@chain << 'and' | |
instance_eval &block if block_given? | |
self | |
end | |
def your arg=nil | |
@chain << (arg || 'my') | |
self | |
end | |
def skill_level arg | |
@chain << "skill level is #{arg}" | |
self | |
end | |
def is arg | |
arg | |
end | |
def in arg | |
@chain << "in #{arg}" | |
end | |
def not | |
@chain << 'am not' | |
self | |
end | |
def love *_ | |
@chain << "love #{_.join(', ')}" | |
end | |
def want *_ | |
@chain << "want #{_.join(', ')}" | |
end | |
def if arg, &block | |
@chain << "if I pass" | |
instance_eval &block if block_given? | |
end | |
def well | |
"well" | |
end | |
def work arg | |
"I work #{arg}" | |
end | |
def hello | |
p @chain.join ' ' | |
end | |
end | |
class DataBase | |
def find_developer(platform: :ruby, region: :london) | |
all_developers(platform, region).select do |you| | |
you.are.crazy | |
.and { your.skill_level is :high } | |
.and { you.are.not.in :plumbee } | |
.and { you.love 'ruby', 'rails' } | |
.and { want 'fun', 'money' } | |
.and.if you do | |
your work well | |
end | |
end | |
end | |
private | |
def all_developers(*_) | |
[Developer.new] | |
end | |
end | |
DataBase.new.find_developer(platform: '123').each(&:hello) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ "I am crazy and my skill level is high and I am not in plumbee and love ruby, rails and want fun, money and if I pass I work well"