Array of Types in Ruby -
I am trying to create objects of various types of items and check validity. I need a lot of things so I can do something like this:
tryclasses (in) type = [Foo :: A, Foo :: B, Foo :: C] types.each Do it Type | Return to A = Type.New (in)! = Null End End
How do I create class types and create an array? By doing this, I am getting no motter (undefined method 'A' for Foo)
Apart from this There are clear syntax errors (such as in
a search term, and zero
spelling zero
in Ruby), the code shown by you will work properly It is, and in fact it does when I copy and paste it into a Ruby installation. It assumes that the classes Foo :: A
, Foo :: B
and Foo :: C
actually exist. If they do not, then this code obviously can not work.
This is completely non-Ruby and simply violates the coding convention in the book:
- Indentation 2 spaces
- Method names
snake_case
, notcamelcase
- clearly
zero
is no-no, simply#nil ?
try_classes
does not really name an intentional disclosure method- and in WTF
/ Code> mean?
- Ruby clearly prefers high-order methods over looping
Here's more RubyShow version of code written by: < Pre>
def can_create_object? (* Args) [Foo :: A, Foo :: B, Foo :: C]. Non? What? Class | Klass.new (* args) .nil? End of End
However, note that I am quite sure that the whole idea is fundamentally flawed.
Comments
Post a Comment