Sha256: cec5ed2230d533ab056728b7d15b9d5002e6789b06d783754cdf6f2511803888
Contents?: true
Size: 1.14 KB
Versions: 1
Compression:
Stored size: 1.14 KB
Contents
# Kernel#instance_variables_from [![[version]](https://badge.fury.io/rb/instance_variables_from.svg)](http://badge.fury.io/rb/instance_variables_from) [![[ci]](https://github.com/janlelis/instance_variable_from/workflows/Test/badge.svg)](https://github.com/janlelis/instance_variable_from/actions?query=workflow%3ATest) Automatically turn bindings, hashes or arrays into instance variables. Instead of: ```ruby def initialize(a, b) @a = a @b = b end ``` You can write: ```ruby def initialize(a, b) instance_variables_from binding # will assign @a and @b end ``` It also works with hashes: ```ruby params = { c: 3, d: 4 } instance_variables_from params # will assign @c and @d ``` It also works with arrays: ```ruby list = %w[instance variable] instance_variables_from list # will assign @_0 and @_1 ``` When you pass additional arguments, they will be interpreted as whitelist: ```ruby params = { c: 3, d: 4 } instance_variables_from params, :c # will only assign @c ``` ## Setup Add to your `Gemfile`: ```ruby gem 'instance_variables_from' ``` ## MIT License Copyright (C) 2010-2016 Jan Lelis <https://janlelis.com>. Released under the MIT license.
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
instance_variables_from-1.0.1 | README.md |