Skip to content

Instantly share code, notes, and snippets.

@ilake
Created March 28, 2013 15:28
Show Gist options
  • Select an option

  • Save ilake/5264065 to your computer and use it in GitHub Desktop.

Select an option

Save ilake/5264065 to your computer and use it in GitHub Desktop.
label_mapping = case state
when "abc", "def"
"label-success"
when "hij", "klm", "opq"
"label-important"
...
...
end
class FooStateLabel
attr_reader :state
def initialize(state)
@state = state
end
def label
send("#{state}_label")
end
%w(abc def).each do |state|
define_method("#{state}_label") do
"label-success"
end
end
...
end
label_mapping = FooStateLabel.new(state).label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment