# Avoiding / handling a method\_missing call

**URL:** <https://www.ruby-forum.com/t/avoiding-handling-a-method-missing-call/153575>\
**Category:** Ruby\
**Created:** [November 18, 2008, 10:35pm UTC](https://www.ruby-forum.com/t/avoiding-handling-a-method-missing-call/153575 "2008-11-18T22:35:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![trevoke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@trevoke](https://www.ruby-forum.com/u/trevoke)\
**Post date:** [November 18, 2008, 10:35pm UTC](https://www.ruby-forum.com/t/avoiding-handling-a-method-missing-call/153575/1 "2008-11-18T22:35:41Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![trevoke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@trevoke](https://www.ruby-forum.com/u/trevoke)\
**Post date:** [November 19, 2008, 4:20am UTC](https://www.ruby-forum.com/t/avoiding-handling-a-method-missing-call/153575/2 "2008-11-19T04:20:31Z")

</div>

On Tue, 18 Nov 2008 17:47:26 -0500, “J. Cooper” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> 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?

---

<div class="post-metadata">

**Author:** ![trevoke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@trevoke](https://www.ruby-forum.com/u/trevoke)\
**Post date:** [November 18, 2008, 11:51pm UTC](https://www.ruby-forum.com/t/avoiding-handling-a-method-missing-call/153575/3 "2008-11-18T23:51:05Z")

</div>

Aldric G. wrote:

> 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
