Skip to content

Instantly share code, notes, and snippets.

@selfup
Created November 24, 2016 13:32
Show Gist options
  • Save selfup/e04020e61448c213921b658c8715ff7c to your computer and use it in GitHub Desktop.
Save selfup/e04020e61448c213921b658c8715ff7c to your computer and use it in GitHub Desktop.
class Rubux
attr_reader :state
def initialize(state = {}, actions = {})
@state = state
@actions = actions
end
def dispatch(key, value)
return @state = @state.merge(@actions[key].(state, value)) if @actions[key]
raise 'no action with that key name is defined'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment