Browse files

Refactor attributes to use each_with_object

  • Loading branch information...
1 parent f75faba commit f3410eb2e1aa29e54678a06c5b46da3856549bc9 @carlosantoniodasilva carlosantoniodasilva committed Jun 25, 2012
Showing with 5 additions and 6 deletions.
  1. +3 −3 lib/mail_form/delivery.rb
  2. +2 −3 lib/mail_form/shim.rb
View
6 lib/mail_form/delivery.rb
@@ -36,10 +36,10 @@ module ClassMethods
# * :validate - A hook to validates_*_of. When true is given, validates the
# presence of the attribute. When a regexp, validates format. When array,
# validates the inclusion of the attribute in the array.
- #
+ #
# Whenever :validate is given, the presence is automatically checked. Give
# :allow_blank => true to override.
- #
+ #
# Finally, when :validate is a symbol, the method given as symbol will be
# called. Then you can add validations as you do in ActiveRecord (errors.add).
#
@@ -148,4 +148,4 @@ def deliver!
MailForm::Notifier.contact(self).deliver
end
end
-end
+end
View
5 lib/mail_form/shim.rb
@@ -32,9 +32,8 @@ def initialize(params={})
# Returns a hash of attributes, according to the attributes existent in
# self.class.mail_attributes.
def attributes
- self.class.mail_attributes.inject({}) do |hash, attr|
+ self.class.mail_attributes.each_with_object({}) do |attr, hash|
hash[attr.to_s] = send(attr)
- hash
end
end
@@ -62,4 +61,4 @@ def deliver
end
alias :save :deliver
end
-end
+end

0 comments on commit f3410eb

Please sign in to comment.