I've been looking at Rails 5.0. It uses an interesting Ruby construct: in class Migration, there is method defined as "def self.[](version)". Now, that's just defining the usual "[]" operator on the class. It's then used like (paraphrased):
class X < Migration[5]
to allow versioning of the Migration class. That seems to make sense.
It works correctly in Rails, but I can't get it to work in my code.
class SetIndexedValue
def self.[](indexSizeBytes)
...
end
...
end
class X < SetIndexedValue[2]
end
This produces an error: superclass must be a Class (NilClass given) (TypeError) on the line "class X...". I'm using Ruby 2.2.5 for both my Rails code and for the code above.
On 16 June 2016 at 11:04, Graham Menhennitt <graham@menhennitt.com.au> wrote:
I've been looking at Rails 5.0. It uses an interesting Ruby construct: in
class Migration, there is method defined as "def self.(version)". Now,
that's just defining the usual "" operator on the class. It's then used
like (paraphrased):
class X < Migration[5]
to allow versioning of the Migration class. That seems to make sense.
It works correctly in Rails, but I can't get it to work in my code.
class SetIndexedValue
def self.(indexSizeBytes)
...
end
...
end
class X < SetIndexedValue[2]
end
This produces an error: superclass must be a Class (NilClass given)
(TypeError) on the line "class X...". I'm using Ruby 2.2.5 for both my
Rails code and for the code above.
On Wednesday, June 15, 2016, 6:12 PM, Matthew Kerwin <matthew@kerwin.net.au> wrote:
Are you returning the class from your . method?
On 16 June 2016 at 11:04, Graham Menhennitt <graham@menhennitt.com.au> wrote:
I've been looking at Rails 5.0. It uses an interesting Ruby construct: in class Migration, there is method defined as "def self.(version)". Now, that's just defining the usual "" operator on the class. It's then used like (paraphrased):
class X < Migration[5]
to allow versioning of the Migration class. That seems to make sense.
It works correctly in Rails, but I can't get it to work in my code.
class SetIndexedValue
def self.(indexSizeBytes)
...
end
...
end
class X < SetIndexedValue[2]
end
This produces an error: superclass must be a Class (NilClass given) (TypeError) on the line "class X...". I'm using Ruby 2.2.5 for both my Rails code and for the code above.
On 16 June 2016 at 11:04, Graham Menhennitt <graham@menhennitt.com.au > <mailto:graham@menhennitt.com.au>> wrote:
I've been looking at Rails 5.0. It uses an interesting Ruby
construct: in class Migration, there is method defined as "def
self.(version)". Now, that's just defining the usual ""
operator on the class. It's then used like (paraphrased):
class X < Migration[5]
to allow versioning of the Migration class. That seems to make sense.
It works correctly in Rails, but I can't get it to work in my code.
class SetIndexedValue
def self.(indexSizeBytes)
...
end
...
end
class X < SetIndexedValue[2]
end
This produces an error: superclass must be a Class (NilClass
given) (TypeError) on the line "class X...". I'm using Ruby 2.2.5
for both my Rails code and for the code above.
irb(main):001:0> def foo
irb(main):002:1> end
=> :foo
irb(main):003:0> class X < foo
irb(main):004:1> end
TypeError: superclass must be a Class (NilClass given)
from (irb):3
from /usr/bin/irb:11:in `<main>'
irb(main):005:0> def bar
irb(main):006:1> Object
irb(main):007:1> end
=> :bar
irb(main):008:0> class Y < bar
irb(main):009:1> end
=> nil
irb(main):010:0> Y.new
=> #<Y:0x000000027f47a0>
I hope this hint is enough to trigger a small epiphany.
Cheers
···
On 16 June 2016 at 12:25, Gnzls <gonzales@flash.net> wrote: