[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

hash map during the creation of a new class instance?

aidy

10/20/2007 11:22:00 AM

Hi,

Is it possible to use a hash map during the creation of a new class
instance?

E.g.

Test_Case_1.new(test = {:name => 'case_1'})

If so, what would the syntax be in the class initialisation method


class Test_Case_1
def initialize(test[:name]) ?

Thank You

Aidy

12 Answers

Robert Klemme

10/20/2007 11:47:00 AM

0

On 20.10.2007 13:22, aidy.lewis@googlemail.com wrote:
> Is it possible to use a hash map during the creation of a new class
> instance?
>
> E.g.
>
> Test_Case_1.new(test = {:name => 'case_1'})

And what should this do?

> If so, what would the syntax be in the class initialisation method
>
>
> class Test_Case_1
> def initialize(test[:name]) ?

As with every method you can this syntax for invoking methods:

irb(main):001:0> def foo(h) h end
=> nil
irb(main):002:0> foo(:name => "hello", :age => 22)
=> {:name=>"hello", :age=>22}

It depends on what you want to do how you would implement initialize here.

Kind regards

robert

aidy

10/20/2007 12:11:00 PM

0

Hi Robert

On 20 Oct, 04:46, Robert Klemme <shortcut...@googlemail.com> wrote:
> On 20.10.2007 13:22, aidy.le...@googlemail.com wrote:
>
>
> > Is it possible to use a hash map during the creation of a new class
> > instance?
>
>
> > E.g.
>
>
> > Test_Case_1.new(test = {:name => 'case_1'})
>
>
> And what should this do?

I was thiking of passing meaningful data into a test case class I have

class Test_Case_1
def initialize() #not sure as yet as to what to enter here

log.detail_test_case(test[:name], .....])

I dont want to hard code the data into the class, and was thinking of
passing test data during initialisation. I could then initialise the
class x number of times with different test data.



>
>
> > If so, what would the syntax be in the class initialisation method
>
>
> > class Test_Case_1
> > def initialize(test[:name]) ?
>
>
> As with every method you can this syntax for invoking methods:
>
>
> irb(main):001:0> def foo(h) h end
> => nil
> irb(main):002:0> foo(:name => "hello", :age => 22)
> => {:name=>"hello", :age=>22}

So, I can put a placeholder in this method

def initialize(x)
>
>
> It depends on what you want to do how you would implement initialize here.
>
My aim is put put test data somewhere meaningful, but for the tests
to be easily read.

log.detail_test_case(test[:name], test[:description])
browser.goto(test[:url])

> Kind regards
>
>
> robert
>
>
Your advice is highly appreciated.

aidy


Robert Klemme

10/20/2007 12:21:00 PM

0

On 20.10.2007 14:11, aidy.lewis@googlemail.com wrote:
> Hi Robert
>
> On 20 Oct, 04:46, Robert Klemme <shortcut...@googlemail.com> wrote:
>> On 20.10.2007 13:22, aidy.le...@googlemail.com wrote:
>>
>>
>>> Is it possible to use a hash map during the creation of a new class
>>> instance?
>>
>>> E.g.
>>
>>> Test_Case_1.new(test = {:name => 'case_1'})
>>
>> And what should this do?
>
> I was thiking of passing meaningful data into a test case class I have
>
> class Test_Case_1
> def initialize() #not sure as yet as to what to enter here
>
> log.detail_test_case(test[:name], .....])
>
> I dont want to hard code the data into the class, and was thinking of
> passing test data during initialisation. I could then initialise the
> class x number of times with different test data.
>
>
>
>>
>>> If so, what would the syntax be in the class initialisation method
>>
>>> class Test_Case_1
>>> def initialize(test[:name]) ?
>>
>> As with every method you can this syntax for invoking methods:
>>
>>
>> irb(main):001:0> def foo(h) h end
>> => nil
>> irb(main):002:0> foo(:name => "hello", :age => 22)
>> => {:name=>"hello", :age=>22}
>
> So, I can put a placeholder in this method
>
> def initialize(x)

"x" is called a "parameter".

http://en.wikipedia.org/wiki/Parameter_%28computer_...

In your case you can simply do

def initialize(test)
log.detail_test_case(test[:name], .....])
end

And then

tc = TestCase1.new(:name => "test 1", :run => 1)

>> It depends on what you want to do how you would implement initialize here.
>>
> My aim is put put test data somewhere meaningful, but for the tests
> to be easily read.
>
> log.detail_test_case(test[:name], test[:description])
> browser.goto(test[:url])
>
>> Kind regards
>>
>>
>> robert
>>
>>
> Your advice is highly appreciated.
>
> aidy

Cheers

robert

Anim8rFSK

7/27/2013 4:24:00 AM

0

In article <MPG.2c5ddbe64725c379989801@news.eternal-september.org>,
David Barnett <dbar3518@bigpond.net.au> wrote:

> COVERT AFFAIRS: Dig For Fire
> Have been posts re this elsewhere.
> I still like the show.
> Kari Matchett as Joan Campbell looked different to me,
> puffier in the face.
> Is she pregnant in real life?

Well, she was; she was due last month

http://www.lifeandstylemag.com/entertainment/news/covert-affair...
chett-pregnant

Let's see ... ah, here we go:

Despite Internet postings that claim she has been married and divorced
from actor James Allodi, they were never married in real life. They only
played a married couple in the film Men With Brooms.

Gave birth to her 1st child at age 43, a son Jude Lyon Matchett in June
2013. Child's father is her ex-boyfriend.

--
Wait - are you saying that ClodReamer was wrong, or lying?

Dano

7/27/2013 2:44:00 PM

0

"David Barnett" wrote in message
news:MPG.2c5ddbe64725c379989801@news.eternal-september.org...



COVERT AFFAIRS: Dig For Fire
Have been posts re this elsewhere.
I still like the show.
Kari Matchett as Joan Campbell looked different to me,
puffier in the face.
Is she pregnant in real life?

======================================

Yes. My wife "Googled" it while we watched as she picked up on it right
away.


Dano

7/27/2013 2:48:00 PM

0

"David Barnett" wrote in message
news:MPG.2c5ddbe64725c379989801@news.eternal-september.org...

KING & MAXWELL: Family Business
I thought King had less stubble on his face in this
episode. What's wrong with being clean shaven?
ISTR posting that I thought Christian Kane was reprising
his character in LEVERAGE>

==============================================

Nah. Kane was much more gregarious and happy-go-lucky as this
character...but he still kicked ass of course. I liked the character. Hope
he recurs...though it didn't appear they intend that. Hope he gets a new
gig out of it. I'm enjoying this one more as it goes on. Interesting guest
characters and a quirky regular cast.


Ian J. Ball

7/27/2013 5:44:00 PM

0

In article <anim8rfsk-2EE65F.21242626072013@news.easynews.com>,
anim8rFSK <anim8rfsk@cox.net> wrote:

> In article <MPG.2c5ddbe64725c379989801@news.eternal-september.org>,
> David Barnett <dbar3518@bigpond.net.au> wrote:
>
> > COVERT AFFAIRS: Dig For Fire
> > Have been posts re this elsewhere.
> > I still like the show.
> > Kari Matchett as Joan Campbell looked different to me,
> > puffier in the face.
> > Is she pregnant in real life?
>
> Well, she was; she was due last month
>
> http://www.lifeandstylemag.com/entertainment/news/covert-affair...
> chett-pregnant
>
> Let's see ... ah, here we go:
>
> Despite Internet postings that claim she has been married and divorced
> from actor James Allodi, they were never married in real life. They only
> played a married couple in the film Men With Brooms.
>
> Gave birth to her 1st child at age 43, a son Jude Lyon Matchett in June
> 2013. Child's father is her ex-boyfriend.

Oh, she's one of those... >:/

--
"Surf-crazed aliens... Of course." - Amber, "Alien Surf Girls",
Episode #1.1, "Wipeout".
Wait a minute... "Of course"?! "*Of course*"?!! Did I miss a step here??!!

David Barnett

7/27/2013 11:08:00 PM

0

In article <anim8rfsk-2EE65F.21242626072013
@news.easynews.com>, anim8rfsk@cox.net says...
>
> In article <MPG.2c5ddbe64725c379989801@news.eternal-september.org>,
> David Barnett <dbar3518@bigpond.net.au> wrote:
>
> > COVERT AFFAIRS: Dig For Fire
> > Have been posts re this elsewhere.
> > I still like the show.
> > Kari Matchett as Joan Campbell looked different to me,
> > puffier in the face.
> > Is she pregnant in real life?
>
> Well, she was; she was due last month
>
> http://www.lifeandstylemag.com/entertainment/news/covert-affair...
> chett-pregnant
>
> Let's see ... ah, here we go:
>
> Despite Internet postings that claim she has been married and divorced
> from actor James Allodi, they were never married in real life. They only
> played a married couple in the film Men With Brooms.
>
> Gave birth to her 1st child at age 43, a son Jude Lyon Matchett in June
> 2013. Child's father is her ex-boyfriend.

Thanks.
So pregnant during the making of the episode (?)

--
David Barnett

Anim8rFSK

7/27/2013 11:28:00 PM

0

In article <MPG.2c5efdf45bfcdda5989804@news.eternal-september.org>,
David Barnett <dbar3518@bigpond.net.au> wrote:

> In article <anim8rfsk-2EE65F.21242626072013
> @news.easynews.com>, anim8rfsk@cox.net says...
> >
> > In article <MPG.2c5ddbe64725c379989801@news.eternal-september.org>,
> > David Barnett <dbar3518@bigpond.net.au> wrote:
> >
> > > COVERT AFFAIRS: Dig For Fire
> > > Have been posts re this elsewhere.
> > > I still like the show.
> > > Kari Matchett as Joan Campbell looked different to me,
> > > puffier in the face.
> > > Is she pregnant in real life?
> >
> > Well, she was; she was due last month
> >
> > http://www.lifeandstylemag.com/entertainment/news/covert-affair...
> > chett-pregnant
> >
> > Let's see ... ah, here we go:
> >
> > Despite Internet postings that claim she has been married and divorced
> > from actor James Allodi, they were never married in real life. They only
> > played a married couple in the film Men With Brooms.
> >
> > Gave birth to her 1st child at age 43, a son Jude Lyon Matchett in June
> > 2013. Child's father is her ex-boyfriend.
>
> Thanks.
> So pregnant during the making of the episode (?)

I'd guess that's where the subplot came from, yeah.

--
Wait - are you saying that ClodReamer was wrong, or lying?

Godzilla Pimp

7/28/2013 4:14:00 AM

0

Dano wrote:
> "David Barnett" wrote in message
> news:MPG.2c5ddbe64725c379989801@news.eternal-september.org...
>
> KING & MAXWELL: Family Business
> I thought King had less stubble on his face in this
> episode. What's wrong with being clean shaven?
> ISTR posting that I thought Christian Kane was reprising
> his character in LEVERAGE>
>
> ==============================================
>
> Nah. Kane was much more gregarious and happy-go-lucky as this
> character...but he still kicked ass of course. I liked the
> character. Hope he recurs...though it didn't appear they intend
> that. Hope he gets a new gig out of it. I'm enjoying this one more
> as it goes on. Interesting guest characters and a quirky regular cast.
>
>
I'm enjoying it more with each episode too... especially dead pan Edgar. ;)

I'd like to see Kane return as well.
bj