Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kgrz/hashish

Adds a #to_hash method to a Class/Struct/OpenStruct that returns a hash based on the method values rather than instance variable values.
https://github.com/kgrz/hashish

Last synced: about 2 months ago
JSON representation

Adds a #to_hash method to a Class/Struct/OpenStruct that returns a hash based on the method values rather than instance variable values.

Awesome Lists containing this project

README

        

# Hashish

TODO: Write a gem description

## Installation

Add this line to your application's Gemfile:

gem 'hashish'

And then execute:

$ bundle

Or install it yourself as:

$ gem install hashish

## Usage

```ruby
class A

include Hashish
attr_reader :a, :b, :c

def initialize(a, b ,c)
@a, @b, @c = a, b, c
end
end
```
and you can do this:

```ruby

a = A.new(1,2,3)
a.to_hash # => {:a => 1, :b => 2, :c => 3}
```

## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request