Question on watir

hi,

do we have anything equivalent to static keyword in C? My motto is value
has to be preserved even after the function return, Global variable is
one of the way to do this, But I guess something equivalent to static
keyword would be a better solution.

RAJ

when i try to print the elements as you have explained, it throws the
same error,

each_element': undefined methodeach’ for nil:NilClass (NoMethodError)

I am trying for Gmail username and password, So can you try to with
Gmail and tell me whether it’s working for you or not?

RAJ

Am 12.04.2013 08:27, schrieb Raj pal:

when i try to print the elements as you have explained, it throws the
same error,

each_element': undefined methodeach’ for nil:NilClass (NoMethodError)

That’s strange because in my example each has not been called
at all…

Anyway: What the error message is trying to convey to you is
that you are trying to call each for an object that is nil:

$ irb
1.9.3p392 :001 > a = nil
=> nil
1.9.3p392 :002 > a.each {|element| puts element }
NoMethodError: undefined method `each’ for nil:NilClass

So, $browser.elements seems to be nil for some reason.

Am 12.04.2013 13:01, schrieb Raj pal:

hi,

do we have anything equivalent to static keyword in C?

RAJ

Please start a new thread for unrelated questions.

$ irb
1.9.3p392 :001 > a = nil
=> nil
1.9.3p392 :002 > a.each {|element| puts element }
NoMethodError: undefined method `each’ for nil:NilClass

So, $browser.elements seems to be nil for some reason.

OK

can you tell me what is the difference between
a=[2,3,3,5]
a=Hash[*b]# It’s converting into hash
a=Hash[b]#it’s converting if a consist of any array

What is the job of “*” here?

And also I would like to know what is the difference does it make for

def hi(*h)
end
def hi(h)
end

RAJ

  • here converts an array to a list of arguments.

so,

in:

args_ary = [1,2]
hash = Hash[*args_ary]

it’s the same as

hash = Hash[1,2]

where as
args_ary = [1,2]
hash = Hash[args_ary]

is the same as

hash=Hash[[1,2]]

… which will give you a bunch of warnings and just set hash to an
empty Hash.

J

The word you’re looking for is “splat”. I found this link quite useful
when I discovered them:

hi,

Class.class==Class

Every class we create is an object of a class Class, but how can Class
itself object of it’s own? Can we create such a class?

RAJ

Class is part of Ruby’s core. Any class you make will be an instance of
Class. As far as I know you could modify class Class but not overwrite
it, although I’d consider that rather dangerous since virtually
everything inherits from Class.

This might help you understand it:

hi Julian L.

Thank you .I understood what you meant.

hi Joel P.

Yes this is what I expected.thank you.

Because the implementation is written in C, not Ruby. Ruby works through
an interpreter, and the circular reference there is part of the
framework that the language works through. I don’t think it’s something
you can replicate from within Ruby, only by writing your own
interpreter. Why would you need to, anyway?

Not for my work, Just to know how that is possible. Because i haven’t
seen such an implemention so far.

Yep this is ok, this i understood. My main focus is, how can Class be
instance of it’s own? Class.class=Class.
Can we able to create a class like that? Instance is only possible after
declaration of class, But here Class is an instance of Class as well.
How it’s possible?

RAJ

I understood what you meant.