-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Class inheritance from Array(T) with YAML.mapping in T #3238
Comments
More generally, this works: class Foo
def initialize(x : Int32)
end
def self.new(x : Char)
end
end
class Bar < Foo
end
Bar.new('a') But this doesn't: class Foo(T)
def initialize(x : Int32)
end
def self.new(x : Char)
end
end
class Bar < Foo(Int32)
end
Bar.new('a') Something to do with generic classes. As a workaround, you can use this: class Children < Array(Child)
def self.new(pull : YAML::PullParser)
super
end
def self.new(pull : YAML::PullParser)
super do |elem|
yield elem
end
end
end Alternatively, just using |
I want to add method like children # => [#<Child @name="Rob", @age=8>, #<Child @name="Alice", @town="New York", @age=7>]
other_children # => [#<Child @name="Alice", @age=9>, #<Child @name="John", @age=6>]
# some magic method
children | other_children # => [#<Child @name="Rob", @age=8>, #<Child @name="Alice", @town="New York", @age=9>, #<Child @name="John", @age=6>]
What do you mean? |
I mean that you are defining a I would always think twice (or maybe many more times) before subclassing a generic type, specially when subclassing containers. |
Okay, thanks. |
Currently seeing a compiler bug when attempting to compile with raven.cr. Although I'm not convinced entirely that this is an issue with action-controller, it does seem to be considered good practice to stick with composition rather than inheritence for this sort of stuff (crystal-lang/crystal#3238 (comment)). The approach taken was effectively the same as amberframework/amber#930 which fixed the same issue within Amber.
Currently seeing a compiler bug when attempting to compile with raven.cr. Although I'm not convinced entirely that this is an issue with action-controller, it does seem to be considered good practice to stick with composition rather than inheritence for this sort of stuff (crystal-lang/crystal#3238 (comment)). The approach taken was effectively the same as amberframework/amber#930 which fixed the same issue within Amber.
Hello!
I have a code:
And I have a problem:
How I can do that
Children
class?Reproducible on
master
branch.Crystal 0.18.7 (2016-07-04) on Arch Linux.
Thanks.
The text was updated successfully, but these errors were encountered: