Skip to content

Instantly share code, notes, and snippets.

@Toshakins
Last active December 27, 2018 10:56
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 Toshakins/4a9b00ae6c818e9fc09fb3020b93cba7 to your computer and use it in GitHub Desktop.
Save Toshakins/4a9b00ae6c818e9fc09fb3020b93cba7 to your computer and use it in GitHub Desktop.
Method Mapping Demo
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