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


Groups > comp.lang.ruby > #6465

Re: question about a particular routing

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Robert Klemme <shortcutter@googlemail.com>
Newsgroups comp.lang.ruby
Subject Re: question about a particular routing
Date Tue, 21 Feb 2012 23:02:37 +0100
Lines 24
Message-ID <9qiijuF3qsU1@mid.individual.net> (permalink)
References <2e41eaf6-ff9d-4900-be9b-45e3a5ed5def@t5g2000yqk.googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Trace individual.net kf94kOrhAd62YWIB9IdyJQm9OzFTEyDFDeGLo+aXE5cHQx4Uc=
Cancel-Lock sha1:RE4VamuYLQOKcfLySs7C2/s7vtU=
User-Agent Mozilla/5.0 (Windows NT 6.0; WOW64; rv:9.0) Gecko/20111222 Thunderbird/9.0.1
In-Reply-To <2e41eaf6-ff9d-4900-be9b-45e3a5ed5def@t5g2000yqk.googlegroups.com>
Xref x330-a1.tempe.blueboxinc.net comp.lang.ruby:6465

Show key headers only | 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