singleton_attr 1.0.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -4,11 +4,11 @@ http://rubygems.org/gems/singleton_attr
4
4
 
5
5
  # Summary #
6
6
 
7
- Adds methods to declare attribute accessor/reader/writer on singleton instance.
7
+ Adds methods to declare attribute accessor/reader/writer on singleton instance and methods to alias singleton methods.
8
8
 
9
9
  # Description #
10
10
 
11
- Provides :singleton_attr_accessor, :singleton_attr_reader, :singleton_attr_writer, :module_attr_accessor, :module_attr_reader, :module_attr_writer, :class_attr_accessor, :class_attr_reader, :class_attr_writer.
11
+ Provides :singleton_attr_accessor, :singleton_attr_reader, :singleton_attr_writer, :module_attr_accessor, :module_attr_reader, :module_attr_writer, :class_attr_accessor, :class_attr_reader, :class_attr_writer as well as :alias_singleton_method, :alias_module_method, and :alias_class_method.
12
12
 
13
13
  # Install #
14
14
 
@@ -16,7 +16,7 @@ Provides :singleton_attr_accessor, :singleton_attr_reader, :singleton_attr_write
16
16
 
17
17
  # Usage #
18
18
 
19
- Just like :attr_accessor, :attr_reader, :attr_writer but instead of defining an instance method it defines a class/module method.
19
+ Just like :attr_accessor, :attr_reader, :attr_writer, :alias_method but instead of defining an instance method it defines a class/module method.
20
20
 
21
21
  # License #
22
22
 
@@ -1,3 +1,4 @@
1
+ # -*- encoding : utf-8 -*-
1
2
 
2
3
  ###
3
4
  # Adds methods to declare attribute accessors/readers/writers on singletons.
@@ -26,6 +27,12 @@ module ::SingletonAttr
26
27
  return self
27
28
 
28
29
  end
30
+
31
+ #############################
32
+ # attr_singleton_accessor #
33
+ #############################
34
+
35
+ alias_method :attr_singleton_accessor, :singleton_attr_accessor
29
36
 
30
37
  ###########################
31
38
  # singleton_attr_reader #
@@ -50,6 +57,12 @@ module ::SingletonAttr
50
57
 
51
58
  end
52
59
 
60
+ ###########################
61
+ # attr_singleton_reader #
62
+ ###########################
63
+
64
+ alias_method :attr_singleton_reader, :singleton_attr_reader
65
+
53
66
  ###########################
54
67
  # singleton_attr_writer #
55
68
  ###########################
@@ -73,6 +86,24 @@ module ::SingletonAttr
73
86
 
74
87
  end
75
88
 
89
+ ###########################
90
+ # attr_singleton_writer #
91
+ ###########################
92
+
93
+ alias_method :attr_singleton_writer, :singleton_attr_writer
94
+
95
+ ############################
96
+ # alias_singleton_method #
97
+ ############################
98
+
99
+ def alias_singleton_method( alias_name, method_name )
100
+
101
+ singleton_class.instance_eval { alias_method alias_name, method_name }
102
+
103
+ return self
104
+
105
+ end
106
+
76
107
  end
77
108
 
78
109
  ###
@@ -85,6 +116,8 @@ module ::SingletonAttr::Module
85
116
  alias_method :module_attr_accessor, :singleton_attr_accessor
86
117
  alias_method :module_attr_reader, :singleton_attr_reader
87
118
  alias_method :module_attr_writer, :singleton_attr_writer
119
+
120
+ alias_method :alias_module_method, :alias_singleton_method
88
121
 
89
122
  end
90
123
 
@@ -99,6 +132,8 @@ module ::SingletonAttr::Class
99
132
  alias_method :class_attr_reader, :singleton_attr_reader
100
133
  alias_method :class_attr_writer, :singleton_attr_writer
101
134
 
135
+ alias_method :alias_class_method, :alias_singleton_method
136
+
102
137
  end
103
138
 
104
139
  class ::Module
@@ -1,3 +1,4 @@
1
+ # -*- encoding : utf-8 -*-
1
2
 
2
3
  require_relative '../lib/singleton_attr.rb'
3
4
 
@@ -24,6 +25,11 @@ describe ::SingletonAttr do
24
25
  instance.instance_variable_get( :@writer ).should be :value
25
26
  instance.respond_to?( :writer ).should be false
26
27
  end
28
+ it '#alias_singleton_method aliases a method defined for singleton' do
29
+ instance.define_singleton_method( :some_method ) { puts 'method body' }
30
+ instance.alias_singleton_method( :other_method_name, :some_method )
31
+ instance.respond_to?( :other_method_name ).should be true
32
+ end
27
33
  end
28
34
 
29
35
  context 'Module' do
@@ -38,6 +44,9 @@ describe ::SingletonAttr do
38
44
  it 'aliases #singleton_attr_writer to #module_attr_writer' do
39
45
  instance.method( :module_attr_writer ).should == instance.method( :singleton_attr_writer )
40
46
  end
47
+ it 'aliases #alias_singleton_method to #alias_module_method' do
48
+ instance.method( :alias_module_method ).should == instance.method( :alias_singleton_method )
49
+ end
41
50
  end
42
51
 
43
52
  context 'Class' do
@@ -52,6 +61,9 @@ describe ::SingletonAttr do
52
61
  it 'aliases #singleton_attr_writer to #class_attr_writer' do
53
62
  instance.method( :class_attr_writer ).should == instance.method( :singleton_attr_writer )
54
63
  end
64
+ it 'aliases #alias_singleton_method to #alias_class_method' do
65
+ instance.method( :alias_class_method ).should == instance.method( :alias_singleton_method )
66
+ end
55
67
  end
56
68
 
57
69
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: singleton_attr
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-29 00:00:00.000000000 Z
12
+ date: 2013-03-11 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Provides :singleton_attr_accessor, :singleton_attr_reader, :singleton_attr_writer,
15
15
  :module_attr_accessor, :module_attr_reader, :module_attr_writer, :class_attr_accessor,