-1

I have task here: I must create a class which will be like class Struct. I have just started to learn Ruby and don't know how to create it. In my attempts, I was able to create a method that takes arguments and creates an array. Then I have to go through the array and all of the arguments, make the argument class, in which I can bring some value. But I don't know how to create methods that can create classes in Ruby.

I am asking for help if you have an example or know where to find it, I will be grateful!

my attempts:

class Hobbit

  def new(*params)
    "#{params.inspect}"
  end

end
Rustam Gasanov
  • 15,290
  • 8
  • 59
  • 72

1 Answers1

0

So I assume all you want is

And what i want it is an example of a method that can create classes

Check out this question and the accepted answer which shows you how to create a class dynamically given a class name. Let me know if that's what you're looking for.

Community
  • 1
  • 1
Hoa
  • 3,179
  • 1
  • 25
  • 33