You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+40-2Lines changed: 40 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ and provide a nice psuedo-object interface.
5
5
6
6
It has its roots in the `Rash` (specifically the [`rash_alt`](https://github.com/shishi/rash_alt) flavor), which is a special `Mash`, made popular by the `hashie` gem.
7
7
8
-
`SnakyHash::Snake`does inherit from `Hashie::Mash` and adds some additional behaviors.
8
+
Classes that include `SnakyHash::Snake`should inherit from `Hashie::Mash`.
9
9
10
10
## Installation
11
11
@@ -19,7 +19,45 @@ If bundler is not being used to manage dependencies, install the gem by executin
19
19
20
20
## Usage
21
21
22
-
For now, please see specs
22
+
```ruby
23
+
classMySnakedHash < Hashie::Mash
24
+
includeSnakyHash::Snake.new(key_type::string) # or :symbol
Note above that you can access the values via the string, or symbol.
37
+
The `key_type` determines how the key is actually stored, but the hash acts as "indifferent".
38
+
Note also that keys that do not respond to `to_sym`, because they don't have a natural conversion to a Symbol,
39
+
are left as-is.
40
+
41
+
### Stranger Things
42
+
43
+
I don't recommend using these features... but they exist (for now).
44
+
You can still access the original un-snaked camel keys.
45
+
And through them you can even use un-snaked camel methods.
46
+
47
+
```ruby
48
+
snake.key?('VeryFineHat') # => true
49
+
snake['VeryFineHat'] # => 'Feathers'
50
+
snake.VeryFineHat# => 'Feathers', PLEASE don't do this!!!
51
+
snake['VeryFineHat'] ='pop'# Please don't do this... you'll get a warning, and it works (for now), but no guarantees.
52
+
# WARN -- : You are setting a key that conflicts with a built-in method MySnakedHash#VeryFineHat defined in MySnakedHash. This can cause unexpected behavior when accessing the key as a property. You can still access the key via the #[] method.
53
+
# => "pop"
54
+
snake.very_fine_hat ='pop'# => 'pop', do this instead!!!
55
+
snake.very_fine_hat # => 'pop'
56
+
snake[:very_fine_hat] ='moose'# => 'moose', or do this instead!!!
57
+
snake.very_fine_hat # => 'moose'
58
+
snake['very_fine_hat'] ='cheese'# => 'cheese', or do this instead!!!
0 commit comments