Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

stop doing the same calculation over and over

  • Loading branch information...
commit 238ee10c41af267d6c931b9eff4cdad674911a23 1 parent 9104702
@tenderlove tenderlove authored
Showing with 5 additions and 4 deletions.
  1. +5 −4 activerecord/lib/active_record/enum.rb
View
9 activerecord/lib/active_record/enum.rb
@@ -38,15 +38,16 @@ def enum(definitions)
definitions.each do |name, values|
# DIRECTION = { }
const = const_set name.to_s.upcase, {}
+ name = name.to_sym
# def direction=(value) self[:direction] = DIRECTION[value] end
define_method "#{name}=" do |value|
- self[:"#{name}"] = const[value]
+ self[name] = const[value]
end
# def direction() DIRECTION.key self[:direction] end
define_method name do
- const.key self[:"#{name}"]
+ const.key self[name]
end
pairs = values.respond_to?(:each_pair) ? values.each_pair : values.each_with_index
@@ -59,12 +60,12 @@ def enum(definitions)
# def incoming?() direction == 0 end
define_method "#{value}?" do
- self[:"#{name}"] == i
+ self[name] == i
end
# def incoming! update! direction: :incoming end
define_method "#{value}!" do
- update! :"#{name}" => :"#{value}"
+ update! name => value.to_sym
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.