Last active
December 27, 2018 10:56
-
-
Save Toshakins/4a9b00ae6c818e9fc09fb3020b93cba7 to your computer and use it in GitHub Desktop.
Method Mapping Demo
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 Actions | |
def action_a | |
puts 'A' | |
end | |
def action_b | |
puts 'B' | |
end | |
def action_c | |
puts 'C' | |
end | |
end | |
action_object = Actions.new | |
ROLE_TO_ACTION = { | |
alpha: [ | |
action_object.method(:action_a), | |
action_object.method(:action_b), | |
action_object.method(:action_c) | |
], | |
beta: [ | |
action_object.method(:action_a), | |
action_object.method(:action_c) | |
], | |
gamma: [ | |
action_object.method(:action_b) | |
] | |
} | |
puts "Actions" | |
ROLE_TO_ACTION.each do |role, action_list| | |
puts "#{role} role" | |
action_list.map &:call | |
end | |
### Outputs | |
# | |
# | |
# Actions | |
# alpha role | |
# A | |
# B | |
# C | |
# beta role | |
# A | |
# C | |
# gamma role | |
# B |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment