Validate method doesn't recognize another instance method

All,

I am attempting to do some custom validation on my object.

Here is my validate method:

protected
def validate
puts "Do I have the target_list_ids method? " +
self.methods.include?(‘target_list_ids’).to_s

if target_list_ids.nil? || target_list_ids.length == 0
  errors.add_to_base("blah")
end

puts "Do I have the Fax method? " + 

self.methods.include?(‘Fax’).to_s
if Fax.nil?
errors.add_to_base(“blah”)
end
end

and here is the output:

Do I have the target_list_ids method? true
Do I have the Fax method? true
uninitialized constant Fax

So as you can see, I am calling the target_list_ids method without
incident but can’t seem to call the Fax method, which I just showed as
existing.

Can anyone explain to me why my “Fax” method can’t be called in the same
way that my “target_list_ids” method can?

I’ll be reading the validate method.

I love this API where I get to read every bit of source code - it really
enhances my productivity ;).

Thanks,
Wes

Wes G. wrote:

All,

I am attempting to do some custom validation on my object.

Here is my validate method:

protected
def validate
puts "Do I have the target_list_ids method? " +
self.methods.include?(‘target_list_ids’).to_s

if target_list_ids.nil? || target_list_ids.length == 0
  errors.add_to_base("blah")
end

puts "Do I have the Fax method? " + 

self.methods.include?(‘Fax’).to_s
if Fax.nil?
errors.add_to_base(“blah”)
end
end

and here is the output:

Do I have the target_list_ids method? true
Do I have the Fax method? true
uninitialized constant Fax

So as you can see, I am calling the target_list_ids method without
incident but can’t seem to call the Fax method, which I just showed as
existing.

Can anyone explain to me why my “Fax” method can’t be called in the same
way that my “target_list_ids” method can?

I’ll be reading the validate method.

I love this API where I get to read every bit of source code - it really
enhances my productivity ;).

Thanks,
Wes

I notice that if I put parens after Fax, so if Fax().nil?, it seems to
work.

However, why do I have to put parens after one method name but not the
other?

Oh my God, it’s because Fax is capitalized, isn’t it? Oh boy…

Thanks,
Wes

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs