[Wtr-general] Solution for FAQ "Using key/value pairs" not working

2007-05-10 Thread Vipul
hi 

i have tried following

class initialValues
@@user_name = 'atilla'
@@last_name = 'ozgur'
  end
 save in intial.rb file. 

But when i use intial.rb file in main file i get syntax error ' 
class/modulename must be a constant.'

Also @@ means global variable inside class?
___
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general


[Wtr-general] Solution for FAQ "Using key/value pairs" not working

2007-05-14 Thread aidy lewis
>On 14/05/07, Vipul <[EMAIL PROTECTED]> wrote:

> class LoginInput
>@@userName = "Vipul.Goyal"
>  end


> $ie.text_field(:id,"txtLoginID").set(LoginInput.userName)


I think the OO idea is that the client should not be able to directly
access a variable outside a class.


class Login_Input
  attr_reader :user_name
  def initialize
@user_name = "Vipul.Goyal"
  end
end

login_input = Login_Input.new
p login_input.user_name


Though, I would be interested in other opinions on this.


aidy
___
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general


Re: [Wtr-general] Solution for FAQ "Using key/value pairs" not working

2007-05-11 Thread aidy lewis
> class initialValues

Use an upper case 'I' for class name.

@@ means class variable.

Aidy

On 11/05/07, Vipul <[EMAIL PROTECTED]> wrote:
> hi
>
> i have tried following
>
> class initialValues
>@@user_name = 'atilla'
>@@last_name = 'ozgur'
>  end
>  save in intial.rb file.
>
> But when i use intial.rb file in main file i get syntax error ' 
> class/modulename must be a constant.'
>
> Also @@ means global variable inside class?
> ___
> Wtr-general mailing list
> Wtr-general@rubyforge.org
> http://rubyforge.org/mailman/listinfo/wtr-general
>
___
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general


Re: [Wtr-general] Solution for FAQ "Using key/value pairs" not working

2007-05-11 Thread Vipul
now i am getting following exception

'undefined method `user_Name' for LoginInput:Class (NoMethodError)'

in main source file contains the code

require 'Input.rb'
 $ie = IE.new()
$ie.goto(test_site)
$ie.text_field(:id,"txtLoginID").set(LoginInput.user_Name)
___
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general


Re: [Wtr-general] Solution for FAQ "Using key/value pairs" not working

2007-05-11 Thread Charley Baker

Looks like user_Name is not defined for your LoginInput class. Check your
casing and make sure it exists there. Might be something like user_name, not
user_Name. Otherwise we'd have to have more information on your LoginInput
class.

-Charley

On 5/11/07, Vipul <[EMAIL PROTECTED]> wrote:


now i am getting following exception

'undefined method `user_Name' for LoginInput:Class (NoMethodError)'

in main source file contains the code

require 'Input.rb'
$ie = IE.new()
$ie.goto(test_site)
$ie.text_field(:id,"txtLoginID").set(LoginInput.user_Name)
___
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general

___
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general

Re: [Wtr-general] Solution for FAQ "Using key/value pairs" not working

2007-05-13 Thread Vipul
yes i have checked the casing

input.rb

class LoginInput
@@userName = "Vipul.Goyal"
  end

main.rb

$ie.text_field(:id,"txtLoginID").set(LoginInput.userName)

exception

'undefined method `userName' for LoginInput:Class (NoMethodError)'
___
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general


Re: [Wtr-general] Solution for FAQ "Using key/value pairs" not working

2007-05-14 Thread aidy lewis
On 14/05/07, Vipul <[EMAIL PROTECTED]> wrote:

> class LoginInput
>@@userName = "Vipul.Goyal"
>  end

> $ie.text_field(:id,"txtLoginID").set(LoginInput.userName)

I think the OO idea is that the client should not be able to directly
access a variable outside a class.


class Login_Input
   attr_reader :user_name
   def initialize
 @user_name = "Vipul.Goyal"
   end
end

login_input = Login_Input.new
p login_input.user_name


Though, I would be interested in other opinions on this.

aidy
___
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general


Re: [Wtr-general] Solution for FAQ "Using key/value pairs" not working

2007-05-14 Thread Charley Baker

Ah,  you're using a class variable and you have no accessor methods so it's
only available to . You'll need to add a class accessor or an instance
method if you're creating object of type LoginInput to get at the value:

class LoginInput
 @@user_name = "Vipul.Goyal"

 def LoginInput.user_name
   @@user_name
 end
end

puts LoginInput.user_name
=> "Vipul.Goyal"

# Now with instance:
class LoginInput
 @@user_name = "Vipul.Goyal"

 def user_name
   @@user_name
 end
end

l = LoginInput.new
puts l.user_name
=> "Vipul.Goyal"



-Charley

On 5/14/07, aidy lewis <[EMAIL PROTECTED]> wrote:


>On 14/05/07, Vipul <[EMAIL PROTECTED]> wrote:

> class LoginInput
>@@userName = "Vipul.Goyal"
>  end


> $ie.text_field(:id,"txtLoginID").set(LoginInput.userName)


I think the OO idea is that the client should not be able to directly
access a variable outside a class.


class Login_Input
  attr_reader :user_name
  def initialize
@user_name = "Vipul.Goyal"
  end
end

login_input = Login_Input.new
p login_input.user_name


Though, I would be interested in other opinions on this.


aidy
___
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general

___
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general

Re: [Wtr-general] Solution for FAQ "Using key/value pairs" not working

2007-05-14 Thread aidy lewis
On 14/05/07, Charley Baker <[EMAIL PROTECTED]> wrote:
> class LoginInput
>   @@user_name = "Vipul.Goyal"
>
>   def LoginInput.user_name
> @@user_name
>   end
> end
>
> puts LoginInput.user_name
> => "Vipul.Goyal"
>
> # Now with instance:
> class LoginInput
>   @@user_name = "Vipul.Goyal"
>
>   def user_name
> @@user_name
>   end
> end
>
> l = LoginInput.new
> puts l.user_name
> => "Vipul.Goyal"

Hi Charley,

I looked at this http://www.rubycentral.com/book/tut_classes.html and
it seems to validate the structure of your code. My question then is;
does Ruby not allow short-cut accessor methods (attr_reader,
attr_writer, attr_accessor) for class variables? And if so, why are
they created and used only for instance variables?

cheers

aidy
___
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general


Re: [Wtr-general] Solution for FAQ "Using key/value pairs" not working

2007-05-14 Thread Charley Baker

Hey aidy,

 There aren't any attribute accessors for class variables. Why? You could I
suppose, but you'd want to keep them accessible only by methods in the
class. I think I'm starting to understand your general question or I could
be totally offbase.

 Say for instance to take a classic example you want to figure out how many
times your class is being used. This is a pretty trivial example but I hope
will illustrate the point.

class MyClass
 @@users = 0

 def initialize
   @@users +=1
   puts "This could do something more useful" if @@users > 1 # this could
exit refuse new instances, etc
 end

 def count
   puts @@users
 end
end


m1 = MyClass.new
m1.count
=> 1
m2 = MyClass.new
=> "This could do something more useful"

The class itself in this case is responsible for it's own information. What
if you were able to set it from some other code through accessors?
some code
MyClass.users += 1
...oops, my code died, i didn't have the chance to remove myself as a user
...worse yet, i maxed the connections to the MyClass and it's not creating
new instances from other people's code.

Hope that makes some sense.

-Charley



On 5/14/07, aidy lewis <[EMAIL PROTECTED]> wrote:


On 14/05/07, Charley Baker <[EMAIL PROTECTED]> wrote:
> class LoginInput
>   @@user_name = "Vipul.Goyal"
>
>   def LoginInput.user_name
> @@user_name
>   end
> end
>
> puts LoginInput.user_name
> => "Vipul.Goyal"
>
> # Now with instance:
> class LoginInput
>   @@user_name = "Vipul.Goyal"
>
>   def user_name
> @@user_name
>   end
> end
>
> l = LoginInput.new
> puts l.user_name
> => "Vipul.Goyal"

Hi Charley,

I looked at this http://www.rubycentral.com/book/tut_classes.html and
it seems to validate the structure of your code. My question then is;
does Ruby not allow short-cut accessor methods (attr_reader,
attr_writer, attr_accessor) for class variables? And if so, why are
they created and used only for instance variables?

cheers

aidy
___
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general

___
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general