Re: Re: ruby equivalent of isset()

18 views
Skip to first unread message

Mukto Mona

unread,
Mar 23, 2016, 1:39:02 AM3/23/16
to rubyonra...@googlegroups.com
Rick Olson wrote in post #29743:
>> The default value is nil, and thus false.
>>
>> if myvar
>> #some code
>> else
>> #default behaviour
>> end
>>
>> Works.
>
> That works with @instance vars, but not local vars. You'll get a
> NameError. You can do this, however:
>
> if defined?(my_var)
> #
> else
> #
> end
>
> --
> Rick Olson
> http://techno-weenie.net

Effective Answer

Mukto

--
Posted via http://www.ruby-forum.com/.
Reply all
Reply to author
Forward
0 new messages