quick_class 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7363b951c04aead144aea53662f003b91e547f375143353b344bb8e18a2ed541
4
- data.tar.gz: 7c87709a125752f1465921607816e6a0a3352f410ed2605188714f24d52824b2
3
+ metadata.gz: 75203a50476ed77a7f7f311f1593a49ac44d24719fe7f6b5ad3aafe1768497fa
4
+ data.tar.gz: b94797c4b5ec5f3d9a4435f532e58592bfc08b96cd28c83b5321a511e070cf76
5
5
  SHA512:
6
- metadata.gz: 910b56e00a944ac972bb05f872a914ac0610e843212769c4af619e7be133ca7117412e1123afd45821278b844de7e19aa0beaa50e8303a0f1c76849cbaf8c11c
7
- data.tar.gz: 16ce25091b6d8e57bd9f9575d0f895daea0cea31daba0d9eac975fb73d4ea3ac2376c3a192d4a8e8d92f4c648e4e004a83ef969eefde26a65b39131e4d8217f1
6
+ metadata.gz: 0006d0cb4caaa7985a24be7740b8f6cfe9dddb4de774f6ab9c5cbbb5e7ecf1bc33624fca6b2a3db1ace7daf90e78119a6974af04a5f3506b1e34dbaa53b61fe0
7
+ data.tar.gz: 0887077a3e6ee7cff85400e9e674463076c7c678da9331b8292249c3e1bead3512f73c328381c6b77636b6079bf0f46ed62fd6ea44e55cad9f7043798166a629
data/README.md CHANGED
@@ -18,14 +18,14 @@ print Foo.attributes
18
18
  ```
19
19
 
20
20
  `initialize` is generated and converted any passed arguments to instance variables.
21
- The instance variables are accessible through generator `attr_accessor` functions.
21
+ The instance variables are accessible through generated `attr_accessor` functions.
22
22
 
23
23
  ```
24
24
  Foo.new
25
- # => #<Foo:0x007ff5e8a70d10>
25
+ # => #<Foo:xxxxxxxxxxxxxxx>
26
26
 
27
27
  foo = Foo.new a: 2
28
- # => #<Foo:0x007ff5e8a70d10 @a=2>
28
+ # => #<Foo:xxxxxxxxxxxxxxx @a=2>
29
29
 
30
30
  foo.a
31
31
  # => 2
@@ -38,9 +38,17 @@ The `default` method is also defined, which is the same as passing `attributes`
38
38
 
39
39
  ```
40
40
  Foo.default
41
- # => #<Foo:0x007fef7398f6b0 @a=0, @b=1>
41
+ # => #<Foo:xxxxxxxxxxxxxxx @a=0, @b=1>
42
42
  ```
43
43
 
44
+ It accepts arguments as well:
45
+
46
+ ```
47
+ Foo.default b: 2
48
+ # => #<Foo:xxxxxxxxxxxxxxx @a=0, @b=2>
49
+ ```
50
+
51
+
44
52
  It works with interitance also:
45
53
 
46
54
  ```
@@ -49,7 +57,7 @@ class Bar < Foo
49
57
  end
50
58
 
51
59
  Bar.default
52
- # => <Bar:0x007f9868906b60 @a=0, @b=1, @c=2>
60
+ # => <Bar:xxxxxxxxxxxxxxx @a=0, @b=1, @c=2>
53
61
  ```
54
62
 
55
63
  Internally, the `attributes=` method is dynamically generating `attr_accessor` and `default` functions.
@@ -10,7 +10,7 @@ class QuickClass
10
10
  # define public attr_accessor methods for all the attributes
11
11
  attr_accessor *@attributes.keys
12
12
  # define a .default method that invokes #initialize with .attributes
13
- define_singleton_method(:default) { new @attributes }
13
+ define_singleton_method(:default) { |**opts| new @attributes.merge(opts) }
14
14
  end
15
15
  # read default attributes
16
16
  def self.attributes; @attributes; end
@@ -1,3 +1,3 @@
1
1
  module QuickClass
2
- VERSION = '1.0.2'
2
+ VERSION = '1.0.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quick_class
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - max pleaner