Avoiding / handling a method_missing call

A

Aldric Giacomoni

I'm trying to retrieve some data from Active Directory
(operatingsystem and operatingsystemservicepack). It so occurs that
-sometimes- that data is nonexistent (Linux box, maybe)... I don't
know how to catch that error (it gives me a method_missing when it
fails) and make it fail gracefully, returning an empty string instead.
What I've done so far is just copy the method_missing from the ldap.rb
to my source code and added an if statement to return '' if the
argument is one of the two mentioned above.. Is there a more elegant
way?

Thanks!
What is the nature of conflict?
 
J

J. Cooper

Aldric said:
I'm trying to retrieve some data from Active Directory
(operatingsystem and operatingsystemservicepack). It so occurs that
-sometimes- that data is nonexistent (Linux box, maybe)... I don't
know how to catch that error (it gives me a method_missing when it
fails) and make it fail gracefully, returning an empty string instead.
What I've done so far is just copy the method_missing from the ldap.rb
to my source code and added an if statement to return '' if the
argument is one of the two mentioned above.. Is there a more elegant
way?

Well, if nothing else, instead of copy-pasting the method_missing from
another class, try delegating to that class:

class MyClass
def method_missing(meth, *args)
case meth
when 'operatingsystem': return ''
# any other special handling
end

object_you_originally_pasted_from.send(meth, args)
end
end
 
A

Aldric Giacomoni

Well, if nothing else, instead of copy-pasting the method_missing from
another class, try delegating to that class:

class MyClass
def method_missing(meth, *args)
case meth
when 'operatingsystem': return ''
# any other special handling
end

object_you_originally_pasted_from.send(meth, args)
end
end

Okay, so ..

class LDAP
def method_missing(meth, *args)
case meth
when 'operatingsystem': return ''
# etc etc
LDAP.send(meth,args)
end
end

is that it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top