nicefn 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +4 -2
- data/README.md +94 -35
- data/lib/inst.rb +18 -4
- data/lib/nicefn.rb +1 -0
- data/lib/sing.rb +16 -7
- data/nicefn.gemspec +19 -9
- metadata +42 -14
- data/.gitignore +0 -7
- data/.travis.yml +0 -8
- data/Gemfile.lock +0 -11
- data/Makefile +0 -35
- data/bin/test +0 -30
- data/exa/after/inst.rb +0 -13
- data/exa/after/sing.rb +0 -9
- data/exa/before/inst.rb +0 -21
- data/exa/before/sing.rb +0 -13
- data/pkg/example_project/Gemfile +0 -3
- data/pkg/example_project/Gemfile.lock +0 -17
- data/pkg/example_project/test.rb +0 -16
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e03ec93935d8b40ddc5ceffef20c30b035be2bd2572f2b87ec737cac6a24aadf
|
|
4
|
+
data.tar.gz: 515e7361e679913a80207e6fc525259f2c1a02fb63aa9f9372b313402944f54e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0e409ae0b12141cf1cdf8fd08bbde73b193630ba468cffe4431feb7d7c651c04f2f68a10d60d6c3992f79391c6721d8cf05898b3dbc0f24d095123cbf523d79c
|
|
7
|
+
data.tar.gz: 92f7c01db2a87d5de7008cca4dfcdd8b7c182e9ccdf33e0c947e8eedd5f7cd9364c5a049ebe36b878bf3acd1255883baa14be1033dd144bae6cee20a3e3efe9e
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -1,18 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
[](https://rubygems.org/gems/nicefn)
|
|
2
|
+
[](https://rubygems.org/gems/nicefn)
|
|
3
|
+
[](https://travis-ci.org/afaur/ruby-nicefn)
|
|
4
|
+
[](https://codeclimate.com/github/afaur/ruby-nicefn/maintainability)
|
|
5
|
+
[](https://codeclimate.com/github/afaur/ruby-nicefn/test_coverage)
|
|
6
|
+
|
|
7
|
+
### Overview
|
|
8
|
+
Here's a way to write functions (with visibility modification) in a single line of ruby.
|
|
9
|
+
```rb
|
|
10
|
+
...
|
|
11
|
+
fp(:priv) { |greet| puts greet }
|
|
12
|
+
...
|
|
13
|
+
```
|
|
14
|
+
This will automatically declare a function with private visibility. Which will
|
|
15
|
+
make it like you had actually wrote:
|
|
16
|
+
```rb
|
|
17
|
+
...
|
|
18
|
+
private
|
|
8
19
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
20
|
+
def priv(greet)
|
|
21
|
+
puts greet
|
|
22
|
+
end
|
|
23
|
+
...
|
|
24
|
+
```
|
|
12
25
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
26
|
+
### Example (Main Scope)
|
|
27
|
+
If you want to write short one-liners in the main scope you need not add this gem
|
|
28
|
+
to your project. It is much quicker and simpler to do:
|
|
29
|
+
```rb
|
|
30
|
+
alias fn define_singleton_method
|
|
31
|
+
|
|
32
|
+
fn(:test) { puts “hello” }
|
|
33
|
+
|
|
34
|
+
test # <= prints "hello" to stdout
|
|
35
|
+
```
|
|
16
36
|
|
|
17
37
|
### Example (Regular Classes)
|
|
18
38
|
Provided below is an example class with `public`, `private`, and `protected` methods:
|
|
@@ -20,59 +40,74 @@ Provided below is an example class with `public`, `private`, and `protected` met
|
|
|
20
40
|
class Inst
|
|
21
41
|
attr_writer :person
|
|
22
42
|
|
|
43
|
+
def self.set_klass_property(value)
|
|
44
|
+
@@klass_property = value
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def self.print_klass_property()
|
|
48
|
+
puts @@klass_property
|
|
49
|
+
end
|
|
50
|
+
|
|
23
51
|
def test_priv(greet)
|
|
24
|
-
priv
|
|
52
|
+
priv greet
|
|
25
53
|
end
|
|
26
54
|
|
|
27
55
|
def test_share(greet, inst)
|
|
28
56
|
inst.share greet
|
|
29
57
|
end
|
|
30
58
|
|
|
31
|
-
private
|
|
59
|
+
private
|
|
60
|
+
|
|
32
61
|
def priv(greet)
|
|
33
62
|
puts "#{greet} #{@person}"
|
|
34
63
|
end
|
|
35
64
|
|
|
36
|
-
protected
|
|
65
|
+
protected
|
|
66
|
+
|
|
37
67
|
def share(greet)
|
|
38
68
|
puts "#{greet} #{@person}"
|
|
39
69
|
end
|
|
40
70
|
end
|
|
41
71
|
```
|
|
42
|
-
If we use `nicefn` on this class we can eliminate
|
|
72
|
+
If we use `nicefn` on this class we can eliminate more than 12 lines of code (if
|
|
73
|
+
we add spaces around private and protected like rubocop suggests) inside of the
|
|
43
74
|
class definition. This is because `private` and `protected` are handled by
|
|
44
75
|
different functions (like `defp` in `elixir`).
|
|
45
76
|
|
|
46
|
-
### After Adding
|
|
77
|
+
### After Adding Nicefn::Inst
|
|
47
78
|
```rb
|
|
48
79
|
require 'nicefn'
|
|
49
80
|
|
|
50
81
|
class Inst
|
|
51
|
-
extend
|
|
82
|
+
extend Nicefn::Inst
|
|
52
83
|
attr_writer :person
|
|
53
84
|
|
|
54
|
-
|
|
55
|
-
|
|
85
|
+
cm(:set_klass_property) { |value| @@klass_property = value }
|
|
86
|
+
cm(:print_klass_property) { puts @@klass_property }
|
|
56
87
|
|
|
57
|
-
|
|
88
|
+
fn(:test_priv) { |greet| priv greet }
|
|
89
|
+
fn(:test_share) { |greet, inst| inst.share greet }
|
|
58
90
|
|
|
59
|
-
|
|
91
|
+
fp(:priv) { |greet| puts "#{greet} #{@person}" }
|
|
92
|
+
|
|
93
|
+
fs(:share) { |greet| puts "#{greet} #{@person}" }
|
|
60
94
|
end
|
|
61
95
|
```
|
|
62
96
|
Calling `fn` with a function `name` and a block will give you a public method.
|
|
63
|
-
|
|
64
|
-
|
|
97
|
+
(**Since version 0.1.1**) Class methods are created using the `cm` function.
|
|
98
|
+
If you call `fp` you will get a `private` method, and `fs` will set a
|
|
99
|
+
`protected` (shared) method.
|
|
65
100
|
|
|
66
101
|
### Example (Singleton Classes)
|
|
67
|
-
Provided below is an example of a
|
|
68
|
-
|
|
102
|
+
Provided below is an example of a `module` that is made a `singleton class` by using
|
|
103
|
+
`extend self`.
|
|
69
104
|
```rb
|
|
70
105
|
module Sing
|
|
71
106
|
extend self
|
|
72
107
|
attr_writer :person
|
|
73
108
|
|
|
74
109
|
def test_priv(greet)
|
|
75
|
-
priv
|
|
110
|
+
priv greet
|
|
76
111
|
end
|
|
77
112
|
|
|
78
113
|
private
|
|
@@ -81,21 +116,45 @@ private
|
|
|
81
116
|
end
|
|
82
117
|
end
|
|
83
118
|
```
|
|
84
|
-
After we add
|
|
85
|
-
extend self as
|
|
119
|
+
After we add `include Nicefn::Sing` to the module we can eliminate the need to
|
|
120
|
+
extend self as `Nicefn::Sing` will do it for us.
|
|
86
121
|
|
|
87
|
-
### After Adding
|
|
122
|
+
### After Adding Nicefn::Sing
|
|
88
123
|
```rb
|
|
89
124
|
require 'nicefn'
|
|
90
125
|
|
|
91
126
|
module Sing
|
|
92
|
-
include
|
|
127
|
+
include Nicefn::Sing
|
|
93
128
|
attr_writer :person
|
|
94
129
|
|
|
95
|
-
fn(:test_priv) {|greet| priv greet}
|
|
96
|
-
fp(:priv) {|greet| puts "#{greet} #{@person}"}
|
|
130
|
+
fn(:test_priv) { |greet| priv greet }
|
|
131
|
+
fp(:priv) { |greet| puts "#{greet} #{@person}" }
|
|
97
132
|
end
|
|
98
133
|
```
|
|
99
134
|
Calling `fn` with a function `name` and a block will give you a public method.
|
|
100
|
-
If you call
|
|
135
|
+
If you call `fp` you will get a `private` method. Since singletons classes can
|
|
101
136
|
only act as one instance 'fs' is not a provided option.
|
|
137
|
+
|
|
138
|
+
## Install Gem
|
|
139
|
+
You can run `bundle add nicefn --version '~> 0.1.0'`, or manually add a line
|
|
140
|
+
indicating how you would like to fetch the `gem` to your `Gemfile`:
|
|
141
|
+
```rb
|
|
142
|
+
...
|
|
143
|
+
# Download latest nicefn from default source
|
|
144
|
+
gem 'nicefn'
|
|
145
|
+
|
|
146
|
+
# Download nicefn from default source with version constraints
|
|
147
|
+
gem 'nicefn', '~> 0.1.0'
|
|
148
|
+
|
|
149
|
+
# Download nicefn from git with a specific version
|
|
150
|
+
gem 'nicefn', git: 'https://github.com/afaur/ruby-nicefn', tag: 'v0.1.0'
|
|
151
|
+
...
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Project Structure
|
|
155
|
+
Running `make` will default to running the tests inside `tst` folder against the
|
|
156
|
+
examples inside the `exa` folder.
|
|
157
|
+
|
|
158
|
+
## How To Use
|
|
159
|
+
Add `extend Nicefn::Inst` to the top of classes. You can also use `include
|
|
160
|
+
Nicefn::Sing` in a `module` to make it a singleton class with `nicefn` methods.
|
data/lib/inst.rb
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
|
-
module
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
# Place the Inst module inside of a namespace
|
|
2
|
+
module Nicefn
|
|
3
|
+
# Adds one-liner instance method/fn declaration capabilities for classes
|
|
4
|
+
module Inst
|
|
5
|
+
define_method(:cm) { |func, &blk| define_singleton_method(func, &blk) }
|
|
6
|
+
|
|
7
|
+
define_method(:fn) { |func, &blk| define_method(func, &blk) }
|
|
8
|
+
|
|
9
|
+
define_method(:fp) do |func, &blk|
|
|
10
|
+
define_method(func, &blk)
|
|
11
|
+
private func
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
define_method(:fs) do |func, &blk|
|
|
15
|
+
define_method(func, &blk)
|
|
16
|
+
protected func
|
|
17
|
+
end
|
|
18
|
+
end
|
|
5
19
|
end
|
data/lib/nicefn.rb
CHANGED
data/lib/sing.rb
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
module
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
define_method(:
|
|
7
|
-
|
|
1
|
+
# Place the Sing module inside of a namespace
|
|
2
|
+
module Nicefn
|
|
3
|
+
# Add one-liner singleton method/fn declaration capabilities for a module
|
|
4
|
+
module Sing
|
|
5
|
+
extend self
|
|
6
|
+
define_method(:included) do |klass|
|
|
7
|
+
klass.extend klass
|
|
8
|
+
|
|
9
|
+
define_method(:fn) { |func, &blk| define_method(func, &blk) }
|
|
10
|
+
|
|
11
|
+
define_method(:fp) do |func, &blk|
|
|
12
|
+
define_method(func, &blk)
|
|
13
|
+
private func
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
8
17
|
end
|
data/nicefn.gemspec
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
lib = File.join(
|
|
1
|
+
ver = '0.1.1'
|
|
2
|
+
lib = File.join(__dir__, 'lib')
|
|
3
3
|
|
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
5
|
|
|
@@ -7,26 +7,34 @@ require 'nicefn'
|
|
|
7
7
|
|
|
8
8
|
Gem::Specification.new do |spec|
|
|
9
9
|
spec.name = 'nicefn'
|
|
10
|
-
spec.version =
|
|
10
|
+
spec.version = ver
|
|
11
11
|
spec.authors = ['afaur']
|
|
12
12
|
spec.email = ['zazu-app@googlegroups.com']
|
|
13
13
|
|
|
14
|
-
spec.summary = %
|
|
15
|
-
|
|
14
|
+
spec.summary = %(This gem adds an alternative way of specifying
|
|
15
|
+
one-liners in your project.)
|
|
16
|
+
|
|
17
|
+
spec.description = %(Elixir and javascript have the capability of making
|
|
16
18
|
good looking one liners, but what about Ruby? We can definitely make an awful
|
|
17
19
|
looking one by adding a ';'. If you want to start defining some better looking
|
|
18
20
|
one-liners then add the 'nicefn' gem to your project. Since the implementation
|
|
19
21
|
files are small and this project has no required deps. You should also feel free
|
|
20
22
|
to copy and paste the implementation directly into your project in an effort to
|
|
21
|
-
avoid extra gems.
|
|
23
|
+
avoid extra gems.)
|
|
22
24
|
|
|
23
25
|
spec.homepage = 'https://github.com/afaur/ruby-nicefn.git'
|
|
24
26
|
spec.license = 'Unlicense'
|
|
25
27
|
|
|
26
28
|
# Specify which files should be added to the gem when it is released.
|
|
27
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been
|
|
30
|
+
# added into git
|
|
31
|
+
spec.files = Dir.chdir(__dir__) do
|
|
32
|
+
# Get all tracked files from git as an array
|
|
33
|
+
git_files = `git ls-files -z`.split("\x0")
|
|
34
|
+
# Remove directories & files that the gem does not use
|
|
35
|
+
git_files
|
|
36
|
+
.reject { |f| f.match(%r{^(tst|exa|bin|pkg)/}) }
|
|
37
|
+
.reject { |f| ['Makefile', '.gitignore', '.travis.yml'].include? f }
|
|
30
38
|
end
|
|
31
39
|
|
|
32
40
|
spec.bindir = 'exe'
|
|
@@ -35,4 +43,6 @@ avoid extra gems.}
|
|
|
35
43
|
|
|
36
44
|
spec.add_development_dependency 'bundler', '~> 1.16'
|
|
37
45
|
spec.add_development_dependency 'rake', '~> 10.0'
|
|
46
|
+
spec.add_development_dependency 'simplecov', '~> 0.16', '>= 0.16.1'
|
|
47
|
+
spec.add_development_dependency 'test-unit', '~> 3.2', '>= 3.2.8'
|
|
38
48
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: nicefn
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- afaur
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-10-
|
|
11
|
+
date: 2018-10-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -38,6 +38,46 @@ dependencies:
|
|
|
38
38
|
- - "~>"
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '10.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: simplecov
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0.16'
|
|
48
|
+
- - ">="
|
|
49
|
+
- !ruby/object:Gem::Version
|
|
50
|
+
version: 0.16.1
|
|
51
|
+
type: :development
|
|
52
|
+
prerelease: false
|
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
54
|
+
requirements:
|
|
55
|
+
- - "~>"
|
|
56
|
+
- !ruby/object:Gem::Version
|
|
57
|
+
version: '0.16'
|
|
58
|
+
- - ">="
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: 0.16.1
|
|
61
|
+
- !ruby/object:Gem::Dependency
|
|
62
|
+
name: test-unit
|
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - "~>"
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '3.2'
|
|
68
|
+
- - ">="
|
|
69
|
+
- !ruby/object:Gem::Version
|
|
70
|
+
version: 3.2.8
|
|
71
|
+
type: :development
|
|
72
|
+
prerelease: false
|
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
74
|
+
requirements:
|
|
75
|
+
- - "~>"
|
|
76
|
+
- !ruby/object:Gem::Version
|
|
77
|
+
version: '3.2'
|
|
78
|
+
- - ">="
|
|
79
|
+
- !ruby/object:Gem::Version
|
|
80
|
+
version: 3.2.8
|
|
41
81
|
description: |-
|
|
42
82
|
Elixir and javascript have the capability of making
|
|
43
83
|
good looking one liners, but what about Ruby? We can definitely make an awful
|
|
@@ -52,25 +92,13 @@ executables: []
|
|
|
52
92
|
extensions: []
|
|
53
93
|
extra_rdoc_files: []
|
|
54
94
|
files:
|
|
55
|
-
- ".gitignore"
|
|
56
|
-
- ".travis.yml"
|
|
57
95
|
- Gemfile
|
|
58
|
-
- Gemfile.lock
|
|
59
96
|
- LICENSE
|
|
60
|
-
- Makefile
|
|
61
97
|
- README.md
|
|
62
|
-
- bin/test
|
|
63
|
-
- exa/after/inst.rb
|
|
64
|
-
- exa/after/sing.rb
|
|
65
|
-
- exa/before/inst.rb
|
|
66
|
-
- exa/before/sing.rb
|
|
67
98
|
- lib/inst.rb
|
|
68
99
|
- lib/nicefn.rb
|
|
69
100
|
- lib/sing.rb
|
|
70
101
|
- nicefn.gemspec
|
|
71
|
-
- pkg/example_project/Gemfile
|
|
72
|
-
- pkg/example_project/Gemfile.lock
|
|
73
|
-
- pkg/example_project/test.rb
|
|
74
102
|
homepage: https://github.com/afaur/ruby-nicefn.git
|
|
75
103
|
licenses:
|
|
76
104
|
- Unlicense
|
data/.gitignore
DELETED
data/.travis.yml
DELETED
data/Gemfile.lock
DELETED
data/Makefile
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
.PHONY: test
|
|
2
|
-
|
|
3
|
-
default: test_all
|
|
4
|
-
|
|
5
|
-
test_example_before_instance:
|
|
6
|
-
@./bin/test before inst
|
|
7
|
-
|
|
8
|
-
test_example_after_instance:
|
|
9
|
-
@./bin/test after inst
|
|
10
|
-
|
|
11
|
-
test_example_before_singleton:
|
|
12
|
-
@./bin/test before sing
|
|
13
|
-
|
|
14
|
-
test_example_after_singleton:
|
|
15
|
-
@./bin/test after sing
|
|
16
|
-
|
|
17
|
-
add_gem:
|
|
18
|
-
@cp pkg/Gemfile ./
|
|
19
|
-
@cp pkg/*.gemspec ./
|
|
20
|
-
|
|
21
|
-
rem_gem:
|
|
22
|
-
@rm Gemfile && rm nicefn.gemspec
|
|
23
|
-
|
|
24
|
-
test_example_project:
|
|
25
|
-
@make add_gem
|
|
26
|
-
@cd pkg/example_project && bundle install && bundle exec ruby test.rb
|
|
27
|
-
@rm pkg/example_project/Gemfile.lock
|
|
28
|
-
@make rem_gem
|
|
29
|
-
|
|
30
|
-
test_all:
|
|
31
|
-
@make test_example_before_instance
|
|
32
|
-
@make test_example_after_instance
|
|
33
|
-
@make test_example_before_singleton
|
|
34
|
-
@make test_example_after_singleton
|
|
35
|
-
@make test_example_project
|
data/bin/test
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
|
|
3
|
-
# Capture stdout
|
|
4
|
-
$stdout = StringIO.new
|
|
5
|
-
|
|
6
|
-
# Enable test running
|
|
7
|
-
require 'test/unit'
|
|
8
|
-
|
|
9
|
-
# Set the name of the object type under test
|
|
10
|
-
object_type_under_test = ARGV[1] == "inst" ? "Instance" : "Singleton"
|
|
11
|
-
|
|
12
|
-
# Set the name of the example under test
|
|
13
|
-
example_under_test = ARGV[0] == "before" ? "Before" : "After"
|
|
14
|
-
|
|
15
|
-
# Define blue color code
|
|
16
|
-
blue_start, blue_end = "\e[36m", "\e[0m"
|
|
17
|
-
|
|
18
|
-
# Test running message
|
|
19
|
-
test_message = "Testing #{object_type_under_test}, #{example_under_test} Example"
|
|
20
|
-
|
|
21
|
-
# Display what test(s) we are currently running
|
|
22
|
-
STDOUT.puts "------------------------------------------------------------\n"
|
|
23
|
-
STDOUT.puts "#{blue_start} #{test_message} #{blue_end}"
|
|
24
|
-
STDOUT.puts "------------------------------------------------------------\n"
|
|
25
|
-
|
|
26
|
-
# Require file under test from argument
|
|
27
|
-
require_relative "../exa/#{ARGV[0]}/#{ARGV[1]}.rb"
|
|
28
|
-
|
|
29
|
-
# Require tests for the example under test
|
|
30
|
-
require_relative "../tst/#{ARGV[1]}.rb"
|
data/exa/after/inst.rb
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
require_relative '../../lib/nicefn.rb'
|
|
2
|
-
|
|
3
|
-
class Inst
|
|
4
|
-
extend Nicefn::Inst
|
|
5
|
-
attr_writer :person
|
|
6
|
-
|
|
7
|
-
fn(:test_priv) {|greet| priv "#{greet}"}
|
|
8
|
-
fn(:test_share) {|greet, inst| inst.share greet}
|
|
9
|
-
|
|
10
|
-
fp(:priv) {|greet| puts "#{greet} #{@person}"}
|
|
11
|
-
|
|
12
|
-
fs(:share) {|greet| puts "#{greet} #{@person}"}
|
|
13
|
-
end
|
data/exa/after/sing.rb
DELETED
data/exa/before/inst.rb
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
class Inst
|
|
2
|
-
attr_writer :person
|
|
3
|
-
|
|
4
|
-
def test_priv(greet)
|
|
5
|
-
priv "#{greet}"
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def test_share(greet, inst)
|
|
9
|
-
inst.share greet
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
private
|
|
13
|
-
def priv(greet)
|
|
14
|
-
puts "#{greet} #{@person}"
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
protected
|
|
18
|
-
def share(greet)
|
|
19
|
-
puts "#{greet} #{@person}"
|
|
20
|
-
end
|
|
21
|
-
end
|
data/exa/before/sing.rb
DELETED
data/pkg/example_project/Gemfile
DELETED
data/pkg/example_project/test.rb
DELETED