On Sun, Feb 10, 2013 at 4:09 AM, tamouse mailing lists
<[email protected]> wrote:
> Something like:
>
> 1.9.3-head :065 > b = a + 1
>
> raises an exception if a is not defined:
>
> NameError: undefined local variable or method `a' for main:Object
>         from (irb):65
>         from /home/tamara/.rvm/rubies/ruby-1.9.3-head/bin/irb:16:in `<main>'
>
> Is there a more elegant way to check if a is defined besides wrapping
> it in begin/rescue/end block? Something along the order of:

You can use a rescue modifier:

$ ruby -e 'b = a + 1 rescue 99; p b'
99

Kind regards

robert

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

-- 
[email protected] | 
https://groups.google.com/d/forum/ruby-talk-google?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"ruby-talk-google" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to