Open thorncp opened 10 years ago
So if we went that direction would we want to duplicate that method on the other environments? I think the behavior on the other environments is more consistent with what we want, but this would make inconsistent implementations for the different environments.
Not sure if that makes any sense.
I'm not convinced this would make inconsistent implementations. The functionality already exists via raw_config
, but the use of Hashes is much more ingrained in Ruby than C# (dunno about Python), and to_h
is the idiomatic way to make the conversion.
However, I do think it would make sense to provide analogous methods for C# (ToDictionary()
?) and Python (no idea).
I'll also refer to #43 and suggest these methods return new objects, so the underlying config cannot be mutated.
If a method uses a hash to handle optional arguments, we cannot currently give it a
Centroid::Config
instance and expect it to work. The case that we ran into is as follows, but there are more if we want to go into them.One workaround on the calling side is to have the method be aware that Centroid exists, and perform checks to determine if it's dealing with a
Centroid::Config
instance. This could also dois_a?(Hash)
,is_a?(Centroid::Config)
, etc., but it will always have the knowledge that Centroid exists (by eitherCentroid::Config
orraw_config
).A workaround on the library side could be to start implementing Hash methods to give the appearance of actually being a Hash. (this is not a good idea)
I think a better idea would be to implement the
to_h
method that simply returns a hash representation, and calling code can rely on that. This moves the code away from knowing anything about Centroid, and just expects you to provide something that can become a Hash.