0

Is this statement enough in Ruby to create a class?

demo = Amiy.new

Will it create a class named Amiy in Ruby?

2 Answers 2

11

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
Sign up to request clarification or add additional context in comments.

Comments

3

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.