Comments (1)
When you subclass ROS, it uses your subclass for the children instances. Since you changed the method signature of initialize
(caught because the arity changed from 2 to 1), it failed when it tried to create a new Config
instance internally (why the exception happened on config.rb:5
where you override initialize
)
You probably want to use composition and not a subclass that changes the method signature of initialize
. Either create a function that accepts a filename and returns an ROS, or create another type called Config
that has an accessor method that returns the ROS data structure.
class Config
def initialize(filename)
@filename = filename
@config = RecursiveOpenStruct.new(YAML.load_file(@filename), {recurse_over_arrays: true, preserve_original_keys: true})
end
attr_accessor :config
end
my_config = Config.new("config.yml")
my_config.config
# => returns the ROS
my_config.config.devices
# => should return the devices sub-ROS
If you don't want the extra accessor in there, you could use a delegator pattern so that your Config
forwards messages it doesn't implement on to the ROS structure.
from recursive-open-struct.
Related Issues (20)
- rspec fails on ruby-head HOT 5
- Not working with Ruby 2.3.0 HOT 2
- 'test' key in source hash breaks RecursiveOpenStruct ros['test'] or ros[:test] HOT 3
- On ros.inspect I can't see my array if recurse_over_arrays: true HOT 4
- on ruby 2.3.1 recurse_over_arrays doesnt work HOT 2
- Make ROS work with Ruby 2.4.x HOT 1
- Drop ruby 2.0 from travis HOT 1
- Doesn't work for a property `test` HOT 6
- Just curious, but why is the implementation here so complicated? HOT 3
- Hash#dig and Hash#fetch patches HOT 7
- Do you follow SemVer? If yes, can you mention it in README/Changelog? HOT 1
- Unknown key with a block returns nil HOT 2
- Freeze is not working + add deep freeze / immutable HOT 2
- tests fail with ruby version 2.7 NoMethodError: undefined method `[]=' for nil:NilClass HOT 2
- Can't serialize ROS as YAML
- undefined method `map' for nil:NilClass
- Unable to deserialize recursively HOT 2
- Some performance numbers
- RecursiveOpenStruct#freeze does not play nice with Ruby 3.1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from recursive-open-struct.