Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

RUBY VALUE OBJECTS

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Gemfile
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 structure.gemspec
README.md

Structure

Turn data (e.g. API responses) into immutable value objects in Ruby.

Usage

Mix in Structure and define values with .value.

class Location
  include Structure

  attr :res

  def initialize(res)
    @res = res
  end

  value :latitude do
    res.fetch(:lat)
  end

  value :longitude do
    res.fetch(:lng)
  end
end

location = Location.new(lat: 10, lng: 100)
location.to_h # {:latitude=>10, :longitude=>100}
Something went wrong with that request. Please try again.