📅 You're Invited: Meet the Socket team at RSAC (April 28 – May 1).RSVP
Socket
Sign inDemoInstall
Socket

fancy-open-struct

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fancy-open-struct

0.4.0
Rubygems
Version published
Maintainers
1
Created
Source

= FancyOpenStruct

{Version}[http://allthebadges.io/tomchapin/fancy-open-struct/badge_fury] {Dependencies}[http://allthebadges.io/tomchapin/fancy-open-struct/gemnasium] {Build Status}[http://allthebadges.io/tomchapin/fancy-open-struct/travis] {Coverage}[http://allthebadges.io/tomchapin/fancy-open-struct/coveralls] {Code Climate}[http://allthebadges.io/tomchapin/fancy-open-struct/code_climate]

FancyOpenStruct is a subclass of OpenStruct, and is a variant of RecursiveOpenStruct.

This gem allows you to convert nested hashes into a structure where keys and values can be navigated and modified via dot-syntax, like: foo.bar = :something. This particular gem also adds support for the Hash methods you know and love (such as length or merge), and also allows you to access and modify the contained data structure the same way that you would handle a normal Hash.

== Usage

FancyOpenStruct allows for hashes within hashes to be called in a chain of methods:

require 'fancy-open-struct'

fos = FancyOpenStruct.new( { :fooa => { :foob => 'fooc' } } )

fos.fooa.foob # => 'fooc'

Also, if needed, nested hashes can still be accessed as hashes:

fos.fooa_as_a_hash # { :foob => 'fooc' }

Get and set values either via dot syntax, or hash syntax (Hash keys are handled as Symbols):

fos = FancyOpenStruct.new

fos.foo = 'bar' fos[:foo] # 'bar'

fos[:baz] = 'qux' fos.baz # 'qux'

fos.length # 2

FancyOpenStruct can also optionally recurse across arrays, although you have to explicitly enable it:

h = { :somearr => [ { :name => 'a'}, { :name => 'b' } ] }

fos = FancyOpenStruct.new(h, :recurse_over_arrays => true )

fos.somarr[0].name # => 'a' fos.somarr[1].name # => 'b'

== Installation

Available as a gem in rubygems, the default gem repository.

If you use bundler, just throw that in your gemfile :

gem 'fancy-open-struct'

You may also install the gem manually :

gem install fancy-open-struct

== Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally.
  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

== Copyright

Copyright (c) 2014 Thomas H. Chapin. See LICENSE for details.

This gem is based on the recursive-open-struct gem by William (B.J.) Snow Orvis, which can be found here: https://github.com/aetherknight/recursive-open-struct

FAQs

Package last updated on 29 May 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts