And also, is you want to have access to @config and @database from the
outside, then as already mentioned then all instance variables (the
ones with @) are private. That means you have to use methods to set
and get the values of those variables. So you could create a methods
like this:
class Web
def config
@config
end
def config=(new_config)
@config = new_config
end
....
end
But, since most of the time the get and set methods are defined just
like the ones above then you can create those methods semi-
automatically by an accessor methods. So, to define an get and set
methods for @config and @database, you can do it like this:
class Web
attr_accessor :config, :database
end
Or if you want just a get methods use "attr_reader" instead. And for a
write-only access "attr_writer".
Enjoy Ruby!
-----
Jarmo Pertman
IT does really matter -
http://www.itreallymatters.net
My declaration will be something like
class Web
Private $conf
Private $database
You don't need to declare the instance variables. And in any case
Private is not a Ruby keyword. And $var is a global variable. Just
remove all the $.
If you want this to be your class' constructor, the method is called
initialize, so
def initialize
@config = parse_ini_file('web/display.ini', true)
@database = @config['Catalog']['database']
end
end
This would be fine.
Will this be a correct Ruby syntax
Summary:
class Web
def initialize
@config = parse_ini_file('web/display.ini', true)
@database = @config['Catalog']['database']
end
end
Jesus.