3den / dot_hash Goto Github PK
View Code? Open in Web Editor NEWAccess hash properties with the dot notation
License: MIT License
Access hash properties with the dot notation
License: MIT License
Would be useful to mention any reasons why someone should consider using this gem over alternatives like OpenStruct (which is in the standard library so it's usually someone's goto). For example, OpenStruct cannot handle nested hashes properly, while this gem can. I didn't know that until trying to find a reason why I would want to use this gem.
Another suggestion is to indicate in an example what happens when a key isn't found. Does it return nil
or does it raise like #fetch
does? If it returns nil
by default, can it be configured to raise?
If you have an "empty" value in a Yaml file an unfriendly error is thrown:
dog:
bark:
bite: "hard"
Settings.dog.bite #=> "hard"
Settings.dog.bark
#=>
NoMethodError: undefined method `bark' for #<Hash:0x007f694ee97de8>
from /home/marsalis/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/dot_hash-0.5.5/lib/dot_hash/properties.rb:45:in `public_send'
I am not sure what the best solution is here. We could 1) set empty values to nil
, or 2) raise a better error message. The error message happens on Hash
not the object itself. This might make it difficult to find the source of the error. In the example, there is only one bark
method. But, if the setting was more generic, like username
or test_mode
, it would be harder to trace the error.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.