hash map during the creation of a new class instance?

A

aidy.lewis

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
 
R

Robert Klemme

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
 
A

aidy.lewis

Hi Robert

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
 
R

Robert Klemme

Hi Robert

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_(computer_science)

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,214
Messages
2,571,112
Members
47,704
Latest member
DavidSuita

Latest Threads

Top