Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #6465

Re: question about a particular routing

From Robert Klemme <shortcutter@googlemail.com>
Newsgroups comp.lang.ruby
Subject Re: question about a particular routing
Date 2012-02-21 23:02 +0100
Message-ID <9qiijuF3qsU1@mid.individual.net> (permalink)
References <2e41eaf6-ff9d-4900-be9b-45e3a5ed5def@t5g2000yqk.googlegroups.com>

Show all headers | View raw


On 21.02.2012 21:30, gerberdata wrote:
> I found this method definition and I was wondering if someone can
> explain it to me or how to use it.
>
> def [](method)
>       self.__send__(method.to_sym)
>     rescue NoMethodError
>       nil
> end

That method allows for conveniently invoking methods by name without 
throwing an error if the method does not exist.  You could invoke method 
"foo" by doing obj["foo"] and do not need to worry for NoMethodError - 
you'll just get nil back.

Oh, and btw "self." is superfluous.

Kind regards

	robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

Back to comp.lang.ruby | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

question about a particular routing gerberdata <gerbdla@gmail.com> - 2012-02-21 12:30 -0800
  Re: question about a particular routing Robert Klemme <shortcutter@googlemail.com> - 2012-02-21 23:02 +0100
    Re: question about a particular routing Mike Austin <mike_ekim@yahoo.com> - 2012-02-21 14:12 -0800
      Re: question about a particular routing Robert Klemme <shortcutter@googlemail.com> - 2012-02-21 23:29 +0100
        Re: question about a particular routing Mike Austin <mike_ekim@yahoo.com> - 2012-02-21 16:07 -0800
        Re: question about a particular routing gerberdata <gerbdla@gmail.com> - 2012-02-21 15:45 -0800

csiph-web