[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Shortcut for "if options.key?(:full)" ?

Peter Alvin

9/23/2008 11:48:00 AM

If I pass an options hash into a def, how do I easily check to see if an
option is set? This is how I'm doing it now:

if options.key?(:some_option)
...
end

Knowing Ruby, there's got to be a cleaner/better way!

Pete
--
Posted via http://www.ruby-....

24 Answers

Robert Klemme

9/23/2008 12:45:00 PM

0

2008/9/23 Peter Alvin <form@awebabove.com>:
> If I pass an options hash into a def, how do I easily check to see if an
> option is set? This is how I'm doing it now:
>
> if options.key?(:some_option)
> ...
> end
>
> Knowing Ruby, there's got to be a cleaner/better way!

If nil is not used as valid option value you can usually do

if options[:some_option]

I don't see how it can become much shorter - unless you rename
"options" and options.

Cheers

robert


--
use.inject do |as, often| as.you_can - without end

Phlip

9/23/2008 4:23:00 PM

0

> if options.key?(:some_option)
> ...
> end
>
> Knowing Ruby, there's got to be a cleaner/better way!

You can generally use options.fetch(:some_option, default) to pass a default
thru without any 'if' statements...

Sanders Kaufman [MCSD]

1/10/2012 2:05:00 PM

0

"DanielSan" <danielsan1977@gmail.com> wrote in message
news:jehfi9$tbh$23@dont-email.me...
> On 1/10/2012 5:45 AM, Mike Cullinan wrote:
>
>> Production of offspring, having children that will become the next
>> generation of adults that human society will depend upon to continue
>> its existence.
>
> That will happen regardless.

Many societies, now long dead, felt that same way.
Today, tourists visit the relics of their skyscrapers, roads, and bustling
cities and marvel at how far they fell.
One of the most notirous societies was that of Nero, who famously fiddled
while Rome burned.

Sanders Kaufman [MCSD]

1/10/2012 2:07:00 PM

0

"DanielSan" <danielsan1977@gmail.com> wrote in message
news:jehfrm$tbh$29@dont-email.me...
> On 1/10/2012 5:49 AM, Sanders Kaufman wrote:
>>>
>>>> You're just unwilling to see the connection.
>>>
>>> There is no connection.
>>
>> It wasn't a negotiation.
>
> Yes, you're right. It's not. So, give up this stupid "cement mixer"
> thing.

That's still negotiating.
You've given up on the logical arguments, now you're trying to bargain your
way through.
The problem with that is that I'm a teacher, not a business man.
Truth is my stock and trade, and I won't trade it for any concession you
might offer.

DanielSan

1/10/2012 2:09:00 PM

0

On 1/10/2012 6:04 AM, Sanders Kaufman wrote:
> "DanielSan" <danielsan1977@gmail.com> wrote in message
> news:jehfi9$tbh$23@dont-email.me...
>> On 1/10/2012 5:45 AM, Mike Cullinan wrote:
>>
>>> Production of offspring, having children that will become the next
>>> generation of adults that human society will depend upon to continue
>>> its existence.
>>
>> That will happen regardless.
>
> Many societies, now long dead, felt that same way.

No, dummy. I said that production of offspring, having children will
happen regardless.

DanielSan

1/10/2012 2:10:00 PM

0

On 1/10/2012 6:07 AM, Sanders Kaufman wrote:
> "DanielSan" <danielsan1977@gmail.com> wrote in message
> news:jehfrm$tbh$29@dont-email.me...
>> On 1/10/2012 5:49 AM, Sanders Kaufman wrote:
>>>>
>>>>> You're just unwilling to see the connection.
>>>>
>>>> There is no connection.
>>>
>>> It wasn't a negotiation.
>>
>> Yes, you're right. It's not. So, give up this stupid "cement mixer"
>> thing.
>
> That's still negotiating.

No, it isn't. It is a complete rejection of your claim.

Sanders Kaufman [MCSD]

1/10/2012 2:10:00 PM

0

"DanielSan" <danielsan1977@gmail.com> wrote in message
news:jehfkh$tbh$24@dont-email.me...
> On 1/10/2012 5:45 AM, Sanders Kaufman wrote:

>> You're dead right about that - it's not just about creating offspring,
>> it's about creating a whole family.
>> Gays can't do that.
>
> Gays can certainly create a family.

Yeah, so can mongoloids - but the results tend to be quite tragic.

DanielSan

1/10/2012 2:16:00 PM

0

On 1/10/2012 6:09 AM, Sanders Kaufman wrote:
> "DanielSan" <danielsan1977@gmail.com> wrote in message
> news:jehfkh$tbh$24@dont-email.me...
>> On 1/10/2012 5:45 AM, Sanders Kaufman wrote:
>
>>> You're dead right about that - it's not just about creating offspring,
>>> it's about creating a whole family.
>>> Gays can't do that.
>>
>> Gays can certainly create a family.
>
> Yeah

Thanks for the concession.

Sanders Kaufman [MCSD]

1/10/2012 2:22:00 PM

0

"DanielSan" <danielsan1977@gmail.com> wrote in message
news:jehfnr$tbh$27@dont-email.me...
> On 1/10/2012 5:48 AM, Sanders Kaufman wrote:

>>> You're content with unconstitutional laws?
>>
>> That's pretty much what the Tea Baggers say about their pet issues, too.
>> That tantrum doesn't sound any more or less rational when you throw it.
>> It just shows that you're as crazy as they - and that I'd be crazy to
>> join you
>
> Explain, if you can.

I did explain.
The problem is that you are unwilling to understand.
Sadly, you're problably perfectly intellectually capable - you just lack the
character to do so.

Look, you may agree or disagree with me and others.
But to say you don't understand what we're saying demonstrates PROFOUND
ignorance.
Your problem isn't that nobody explains stuff to you.
It's just that you're unwilling or unable to understand any of it.

That's what mental illness is all about.

DanielSan

1/10/2012 2:23:00 PM

0

On 1/10/2012 6:21 AM, Sanders Kaufman wrote:
> "DanielSan" <danielsan1977@gmail.com> wrote in message
> news:jehfnr$tbh$27@dont-email.me...
>> On 1/10/2012 5:48 AM, Sanders Kaufman wrote:
>
>>>> You're content with unconstitutional laws?
>>>
>>> That's pretty much what the Tea Baggers say about their pet issues, too.
>>> That tantrum doesn't sound any more or less rational when you throw it.
>>> It just shows that you're as crazy as they - and that I'd be crazy to
>>> join you
>>
>> Explain, if you can.
>
> I did explain.

No, you asserted. There's a difference.

> The problem is that you are unwilling to understand.
> Sadly, you're problably perfectly intellectually capable - you just lack
> the character to do so.
>
> Look, you may agree or disagree with me and others.

The English language disagrees with you and others.