Business application building with Ruby

F

Francis Hwang

zuzu said:
to start with, http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/current-stable.html

FreeBSD (perhaps the *BSDs in general) seem to have defined a standard
for what versioning should mean. not just release vs. current vs.
stable, but also their numbering.

so patterns exist to stablize what versioning should constitute.

I wasn't saying that patterns don't exist. I was saying that consensus
has not been reached.

Personally, whenever I'm checking out new libraries, I always look for
some sort of statement about whether it's alpha, beta, stable,
whatever. Sometimes that's a note on the web page, or a little tag on
the Sourceforge or Rubyforge page.

Is the Ruby community significantly out of step with the broader free
software community on this?

F.
 
A

Alexey Verkhovsky

Result of executing this code:

class MyClass

@instance_variable = "aaa"

def MyClass::class_method
puts @instance_variable
end

end

MyClass.class_method

is "aaa".

I expected it to be "undefined variable".

What is the meaning of instance variable being accessible from a class
method? Which instance holds the value of that variable, if none has
been explicitly created yet?

Best regards,
Alexey Verkhovsky
 
T

ts

A> What is the meaning of instance variable being accessible from a class

a class is an object and like any object it can have instance variable

A> method? Which instance holds the value of that variable, if none has
A> been explicitly created yet?

try this

svg% ruby -e 'class A; p self; @a = 12 end'
A
svg%


the instance variable will be defined for A


Guy Decoux
 
A

Alexey Verkhovsky

a class is an object
This much I understood before.
and like any object it can have instance variable

Aha...

To check my new understanding, @instance_variable in that example is a
variable of MyClass, the object.

Unlike things like @@static_class_attribute (that are also attributes
of MyClass, the object), @instance_variable is not accessible by objects
created by MyClass.new method.

Is that right? Experiments with IRB seem to confirm.

Alex
 
C

CT

Result of executing this code:

class MyClass

@instance_variable = "aaa"

Here, @instance_variable is an instance variable of the class object MyClass.
See: http://www.rubygarden.org/ruby?ClassInstanceVariables

Everything is an object in Ruby, even classes.

You were probably looking for something like:
class MyClass
def initialize
@instance_variable = "aaa"
#this means @instance_variable is an instance variable for
#objects of this class
end

def MyClass::class_method
puts @instance_variable
end
end

In which case MyClass.class_method will print 'nil', as expected.

HTH
- CT
 

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,149
Messages
2,570,842
Members
47,388
Latest member
EarthaGilm

Latest Threads

Top