tags:

views:

80

answers:

3

Is this statement enough in Ruby to create a class?

demo = Amiy.new

Will it create a class named Amiy in Ruby?

+10  A: 

No. What this code does is create an instance (object) of the Amiy class. To create a class you use the class statement:

class Amiy
  # ...
end

Once you've created the class then you can make an instance of it:

my_object = Amiy.new
Jordan
+3  A: 

If you want to declare a new class, you should do as Jordan said and use this syntax:

class Amiy
end

But technically you can do something like this:

Amiy = Class.new
puts "Amiy: #{(Amiy).inspect}"

instance = Amiy.new
puts "instance: #{(instance).inspect}"

Running that will give you something like this:

Amiy: Amiy
instance: #<Amiy:0xb7500b24>
Benjamin Oakes
A: 

I don't want to sound rude, but you should read some (even basic) Ruby book first.

Ghast
This should probably be a comment on the question rather than an answer.
Benjamin Oakes