Skip to content

Commit

Permalink
More symbols for send and respond_to?.
Browse files Browse the repository at this point in the history
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information
Clemens Kofler authored and jeremy committed Sep 2, 2008
1 parent a978701 commit 1646e8c
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion activemodel/lib/active_model/validations/exclusion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def validates_exclusion_of(*attr_names)

enum = configuration[:in] || configuration[:within]

raise(ArgumentError, "An object with the method include? is required must be supplied as the :in option of the configuration hash") unless enum.respond_to?("include?")
raise(ArgumentError, "An object with the method include? is required must be supplied as the :in option of the configuration hash") unless enum.respond_to?(:include?)

validates_each(attr_names, configuration) do |record, attr_name, value|
record.errors.add(attr_name, configuration[:message] % value) if enum.include?(value)
Expand Down
2 changes: 1 addition & 1 deletion activemodel/lib/active_model/validations/inclusion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def validates_inclusion_of(*attr_names)

enum = configuration[:in] || configuration[:within]

raise(ArgumentError, "An object with the method include? is required must be supplied as the :in option of the configuration hash") unless enum.respond_to?("include?")
raise(ArgumentError, "An object with the method include? is required must be supplied as the :in option of the configuration hash") unless enum.respond_to?(:include?)

validates_each(attr_names, configuration) do |record, attr_name, value|
record.errors.add(attr_name, configuration[:message] % value) unless enum.include?(value)
Expand Down
4 changes: 2 additions & 2 deletions activerecord/lib/active_record/attribute_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@ def query_attribute(attr_name)
end
end

# A Person object with a name attribute can ask <tt>person.respond_to?("name")</tt>,
# <tt>person.respond_to?("name=")</tt>, and <tt>person.respond_to?("name?")</tt>
# A Person object with a name attribute can ask <tt>person.respond_to?(:name)</tt>,
# <tt>person.respond_to?(:name=)</tt>, and <tt>person.respond_to?(:name?)</tt>
# which will all return +true+.
alias :respond_to_without_attributes? :respond_to?
def respond_to?(method, include_priv = false)
Expand Down
6 changes: 3 additions & 3 deletions activerecord/lib/active_record/validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def add(attribute, message = nil, options = {})
def add_on_empty(attributes, custom_message = nil)
for attr in [attributes].flatten
value = @base.respond_to?(attr.to_s) ? @base.send(attr.to_s) : @base[attr.to_s]
is_empty = value.respond_to?("empty?") ? value.empty? : false
is_empty = value.respond_to?(:empty?) ? value.empty? : false
add(attr, :empty, :default => custom_message) unless !value.nil? && !is_empty
end
end
Expand Down Expand Up @@ -751,7 +751,7 @@ def validates_inclusion_of(*attr_names)

enum = configuration[:in] || configuration[:within]

raise(ArgumentError, "An object with the method include? is required must be supplied as the :in option of the configuration hash") unless enum.respond_to?("include?")
raise(ArgumentError, "An object with the method include? is required must be supplied as the :in option of the configuration hash") unless enum.respond_to?(:include?)

validates_each(attr_names, configuration) do |record, attr_name, value|
unless enum.include?(value)
Expand Down Expand Up @@ -785,7 +785,7 @@ def validates_exclusion_of(*attr_names)

enum = configuration[:in] || configuration[:within]

raise(ArgumentError, "An object with the method include? is required must be supplied as the :in option of the configuration hash") unless enum.respond_to?("include?")
raise(ArgumentError, "An object with the method include? is required must be supplied as the :in option of the configuration hash") unless enum.respond_to?(:include?)

validates_each(attr_names, configuration) do |record, attr_name, value|
if enum.include?(value)
Expand Down
4 changes: 2 additions & 2 deletions activeresource/lib/active_resource/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -915,8 +915,8 @@ def load(attributes)
alias_method :respond_to_without_attributes?, :respond_to?

# A method to determine if an object responds to a message (e.g., a method call). In Active Resource, a Person object with a
# +name+ attribute can answer <tt>true</tt> to <tt>my_person.respond_to?("name")</tt>, <tt>my_person.respond_to?("name=")</tt>, and
# <tt>my_person.respond_to?("name?")</tt>.
# +name+ attribute can answer <tt>true</tt> to <tt>my_person.respond_to?(:name)</tt>, <tt>my_person.respond_to?(:name=)</tt>, and
# <tt>my_person.respond_to?(:name?)</tt>.
def respond_to?(method, include_priv = false)
method_name = method.to_s
if attributes.nil?
Expand Down

0 comments on commit 1646e8c

Please sign in to comment.