Skip to content

Instantly share code, notes, and snippets.

@jcf
Forked from technoweenie/gist:141882
Created July 7, 2009 08:25
Show Gist options
  • Save jcf/141960 to your computer and use it in GitHub Desktop.
Save jcf/141960 to your computer and use it in GitHub Desktop.
# exhibit a
{:conditions => case f.to_s
when 'active' then {:state => @@states[2]}
when 'disabled' then {:state => @@states[0..1]}
when 'all' then {}
else {:state => @@states[3]}
end}
# exhibit b
case f.to_s
when 'active' then {:conditions => {:state => @@states[2]}}
when 'disabled' then {:conditions => {:state => @@states[0..1]}}
when 'all' then {}
else {:conditions => {:state => @@states[3]}}
end
# exhibit c
return if f.to_s == 'all'
state = case f.to_s
when 'active' then @@states[2]
when 'disabled' then @@states[0..1]
else @@states[3]
end
{:conditions => {:state => state}} # I shouldn't have forgotten this!
# exhibit d
# Everyone loves Hash!
@@states = {'active' => {'some' => 'conditions'},
'disabled' => {'other' => 'conditions'}}
@@states[f].nil?? {} : {:conditions => {:state => @@states[f]}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment