settable_constructor_variables 1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc ADDED
@@ -0,0 +1,27 @@
1
+ Allows you to set instance variables through constructor parameters. Dead simple but resolves an annoyance.
2
+
3
+ require 'settable_constructor_variables'
4
+
5
+ class MyClass
6
+ include SettableConstructorVariables
7
+ attr_accessor :something
8
+ end
9
+
10
+ MyClass.new(something: 'abc').something #=> 'abc'
11
+
12
+ To use this in conjunction with your own constructor...
13
+
14
+ class MyClass
15
+ include SettableConstructorVariables
16
+ attr_accessor :something
17
+
18
+ def initialize params
19
+ # do something
20
+ super params
21
+ # do something else
22
+ end
23
+ end
24
+
25
+ Tinniest gem ever and having put the effort in to make it a gem, I am wondering how worthwhile the effort was...
26
+
27
+ ... And now I wait for somebody to tell me it has already been done!
@@ -0,0 +1,7 @@
1
+ module SettableConstructorVariables
2
+ def initialize params = {}
3
+ params.each do |key, value|
4
+ instance_variable_set "@#{key}", value
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module SettableConstructorVariables
2
+ VERSION = '1'
3
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: settable_constructor_variables
3
+ version: !ruby/object:Gem::Version
4
+ version: '1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Stephen Hardisty
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: &70119938503740 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70119938503740
25
+ description: Hyper lazy way of setting instance variables automatically by passing
26
+ them to your constructor. Least clever gem ever?
27
+ email:
28
+ - moowahaha@hotmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/settable_constructor_variables/version.rb
34
+ - lib/settable_constructor_variables.rb
35
+ - README.rdoc
36
+ homepage: http://github.com/moowahaha/settable_constructor_variables
37
+ licenses: []
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 1.3.6
54
+ requirements: []
55
+ rubyforge_project:
56
+ rubygems_version: 1.8.10
57
+ signing_key:
58
+ specification_version: 3
59
+ summary: Set instance variables from constructor parameters without doing it yourself.
60
+ test_files: []