Forum: Ruby What do you call this part of an object?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Mmcolli00 M. (Guest)
on 2008-12-10 20:00
What do you call this part of an object? @action== positions=0,0
elements="\n","\n". Thanks in advance.

My Object
[#<Diff::LCS::ContextChange:24251690 @action== positions=0,0
elements="\n","\n">
Brian C. (Guest)
on 2008-12-11 11:02
Mmcolli00 Mom wrote:
> What do you call this part of an object? @action== positions=0,0
> elements="\n","\n". Thanks in advance.

They are instance variables.

class Foo
  attr_accessor :x, :y
  def initialize(x,y)
    @x = x
    @y = y
  end
  def say_something
    puts "@x is #{@x} and @y is #{@y}"
  end
end

f = Foo.new("hello", "world")
puts f.inspect
f.say_something

# Using the accessor methods which attr_accessor adds
f.x = "goodbye"
puts f.x
puts f.y

You really need to understand instance variables, classes and methods if
you are going to start programming in Ruby. I suggest you start here:
http://www.ruby-doc.org/docs/ProgrammingRuby/

(If you want a paper or PDF book, there are newer versions of this book
available from www.pragprog.com)
Mmcolli00 M. (Guest)
on 2008-12-11 23:25
Thanks Brian.
This topic is locked and can not be replied to.