[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

passing hash as arguments

Jason

1/27/2009 6:23:00 AM

Is this the best way (though contrived) to use a hash as an argument in
ruby?

def state_name_age(feeling, info{})
"#{:name} is #{feeling} #{:age} #{:units} old"
end

my_info = {}
my_info = {:name => "Kate", :units => "years", :age => 24}

irb(main):018:0> state_name_age('happily', my_info)
=> "Kate is happily 24 years old"

then...

irb(main):068:0> state_name_age 'happily'
=> " is happily old!"

This seems to be the way Rails has things set up to pass optional
arguments... Is that correct?
--
Posted via http://www.ruby-....

2 Answers

ThoML

1/27/2009 6:31:00 AM

0

> def state_name_age(feeling, info{})
> =A0 "#{:name} is #{feeling} #{:age} #{:units} old"
> end

Try:

def state_name_age(feeling, info=3D{})
"#{info[:name]} is #{info[feeling]} #{info[:age]} #{info[:units]}
old"
end

irb(main):018:0> state_name_age('happily', :name =3D> "Kate", :units =3D>
"years", :age =3D> 24)

RyanH

12/17/2009 7:49:00 PM

0

Do you see a "YES" button next to Was this post helpful to you?
Someone told me that they don't see it so they can't give credit to those
that help with code. I saw your reply about "Thanks" but not check mark by
our names. I'm just curious.


--
Cheers,
Ryan


"Bob A" wrote:

> wow, thank you VERY much for your great help!
> --
> Bob A
>
>
> "Mike H" wrote:
>
> > Hi,
> >
> > There are several ways, this loops through an array of named sheets
> >
> > Sub Sonic()
> > Dim V As Variant
> > Dim S As String
> > Dim sh As Worksheet
> > S = "Sheet1,Sheet2,Sheet3"
> > V = Split(S, ",")
> > For Each sh In ThisWorkbook.Worksheets
> > If Not IsError(Application.Match(CStr(sh.Name), V, 0)) Then
> > 'do things
> > MsgBox sh.Name
> > End If
> > Next sh
> > End Sub
> >
> >
> > Mike
> >
> > "Bob A" wrote:
> >
> > > I need to write code that automatically moves from sheet to sheet and gathers
> > > data. I have no problem gathering the data on the sheet but I don't know how
> > > to move the pointer to the next sheet in the workbook.
> > > I would really appreciate any help you can give.
> > > --
> > > Bob A