KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
This question is strictly about Struct behavior, so please no "why in the wide world of sports are you doing it that way?" This code is INCORRECT, but it should illustrate what I am trying to understand about Ruby Structs: class Person < Struct.new(:name, :last_name) end class ReligiousPerson < Person(:religion) end class PoliticalPerson < Person(:political_affiliation) end ### Main ### person = Person.new('jackie', 'jack') pious_person = ReligiousPerson.new('billy', 'bill', 'Zoroastrianism') political_person = PoliticalPerson.new('frankie', 'frank', 'Connecticut for Lieberman') As you can see, there's an attempt to define a class inheritance using Structs. However, Ruby gets cranky when you try to initialize ReligiousPerson or PoliticalPerson, of course. So given this illustrative code, how is it possible to inherit named params using this type of class inheritance using Structs?
Tags (comma-separated)
Save Edits
Cancel