spaces_are_ok 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.ruby-version +1 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +281 -0
- data/Rakefile +7 -0
- data/lib/spaces_are_ok.rb +17 -0
- data/lib/spaces_are_ok/classes_and_modules.rb +63 -0
- data/lib/spaces_are_ok/dont_worry_about_spelling.rb +12 -0
- data/lib/spaces_are_ok/methods.rb +27 -0
- data/lib/spaces_are_ok/modify_the_kernel.rb +40 -0
- data/lib/spaces_are_ok/version.rb +3 -0
- data/spaces_are_ok.gemspec +25 -0
- data/test.rb +130 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 50b5c8bb4f715deea3aad77d77a806731f68764c
|
4
|
+
data.tar.gz: e1330ea83d035cdc61930038fe2468ff23500086
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4921e3819e2a031290432f24b20c588784499f16801237d4e8a527af72871fe68178fead26526fbbc284391a4791c05788290b99b7dda3b76785f132c41b5c23
|
7
|
+
data.tar.gz: eb9afc71b9867e2d3c54db88d0a67efdfe7bd93aa871b12d51a00b5c4d7cedb11a48340041b585eff78f0f1605563714dbd0ca8cf92392111e26fe47a5c50d79
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.5
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Kim Ahlström
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,281 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/Kimtaro/spaces_are_ok.svg)](https://travis-ci.org/Kimtaro/spaces_are_ok) [![Code Climate](https://codeclimate.com/github/Kimtaro/spaces_are_ok/badges/gpa.svg)](https://codeclimate.com/github/Kimtaro/spaces_are_ok) [![Test Coverage](https://codeclimate.com/github/Kimtaro/spaces_are_ok/badges/coverage.svg)](https://codeclimate.com/github/Kimtaro/spaces_are_ok)
|
2
|
+
|
3
|
+
# Spaces Are Ok
|
4
|
+
|
5
|
+
Use natural language in your Ruby class and method names.
|
6
|
+
|
7
|
+
Like this
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
space_class("Scorecard for a player").new("Picard").space_method("Calculate the score from a game", game)
|
11
|
+
```
|
12
|
+
|
13
|
+
or the shorter and fancier
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
ç("Scorecard for a player").new("Picard").ƒ("Calculate the score from a game", game)
|
17
|
+
```
|
18
|
+
|
19
|
+
instead of the mechanical and boring
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
ScorecardForPlayer.new("Picard").calculate_new_score(game)
|
23
|
+
```
|
24
|
+
|
25
|
+
or the not very informative
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
Scorecard.new("Picard").score(game)
|
29
|
+
```
|
30
|
+
|
31
|
+
## Why
|
32
|
+
|
33
|
+
Naming things is famously one of the hard things in computer science[*](http://martinfowler.com/bliki/TwoHardThings.html), but programming languages aren't doing a very good job of helping us write fun and descriptive language.
|
34
|
+
|
35
|
+
What if instead of `WritingLikeThis`, `having_to_read_this` or `BEING_SHOUTEN_AT` we could write and read regular language? Maybe it will help us write better programs? Or maybe it won't. But I thought it would be a fun experiment.
|
36
|
+
|
37
|
+
## Installation
|
38
|
+
|
39
|
+
This gem requires Ruby 2.1 or newer.
|
40
|
+
|
41
|
+
Add this line to your application's Gemfile:
|
42
|
+
|
43
|
+
gem 'spaces_are_ok'
|
44
|
+
|
45
|
+
And then execute:
|
46
|
+
|
47
|
+
$ bundle
|
48
|
+
|
49
|
+
Or install it yourself as:
|
50
|
+
|
51
|
+
$ gem install spaces_are_ok
|
52
|
+
|
53
|
+
## Usage
|
54
|
+
|
55
|
+
Ruby doesn't allow method calls with the keywords `class` and `def`, so we have to use slightly different syntax when defining and using our space friendly names. But it's not too bad.
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
require 'spaces_are_ok'
|
59
|
+
|
60
|
+
space_class("Greet someone") do
|
61
|
+
def initialize(name)
|
62
|
+
@name = name
|
63
|
+
end
|
64
|
+
|
65
|
+
space_method_def "Say hello", def _
|
66
|
+
"Hello, #{@name}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
greeter = space_class("Greet someone").new("Kim")
|
71
|
+
greeter.space_method("Say hello") # => Hello, Kim!
|
72
|
+
```
|
73
|
+
|
74
|
+
Since it gets rather tedious to write `space_` all the time, I have included shorthand versions, so the above can be written like this:
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
require 'spaces_are_ok'
|
78
|
+
|
79
|
+
ç("Greet someone") do
|
80
|
+
def initialize(name)
|
81
|
+
@name = name
|
82
|
+
end
|
83
|
+
|
84
|
+
∂ƒ "Say hello", def _
|
85
|
+
"Hello, #{@name}"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
greeter = ç("Greet someone").new("Kim")
|
90
|
+
greeter.ƒ("Say hello") # => Hello, Kim!
|
91
|
+
```
|
92
|
+
|
93
|
+
### Summary of functionality
|
94
|
+
|
95
|
+
#### Defining a class
|
96
|
+
|
97
|
+
##### Plain Ruby
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
class LaunchSpaceShip
|
101
|
+
# Class definition
|
102
|
+
end
|
103
|
+
```
|
104
|
+
|
105
|
+
##### Spaces Are Ok
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
space_class("Launch space ship") do
|
109
|
+
# Class definition
|
110
|
+
end
|
111
|
+
```
|
112
|
+
|
113
|
+
##### Spaces Are Ok shorthand
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
ç("Launch space ship") do
|
117
|
+
# Class definition
|
118
|
+
end
|
119
|
+
```
|
120
|
+
|
121
|
+
#### Using a class
|
122
|
+
|
123
|
+
##### Plain Ruby
|
124
|
+
|
125
|
+
```ruby
|
126
|
+
LaunchSpaceShip.new
|
127
|
+
```
|
128
|
+
|
129
|
+
##### Spaces Are Ok
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
space_class("Launch space ship").new
|
133
|
+
```
|
134
|
+
|
135
|
+
##### Spaces Are Ok shorthand
|
136
|
+
|
137
|
+
```ruby
|
138
|
+
ç("Launch space ship").new
|
139
|
+
```
|
140
|
+
|
141
|
+
#### Defining a module
|
142
|
+
|
143
|
+
#####Plain Ruby
|
144
|
+
|
145
|
+
```ruby
|
146
|
+
module SpaceShipMotor
|
147
|
+
# Module definition
|
148
|
+
end
|
149
|
+
```
|
150
|
+
|
151
|
+
##### Spaces Are Ok
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
space_module("Space ship motor") do
|
155
|
+
# Module definition
|
156
|
+
end
|
157
|
+
```
|
158
|
+
|
159
|
+
##### Spaces Are Ok shorthand
|
160
|
+
|
161
|
+
```ruby
|
162
|
+
ɱ("Space ship motor") do
|
163
|
+
# Module definition
|
164
|
+
end
|
165
|
+
```
|
166
|
+
|
167
|
+
#### Using a module
|
168
|
+
|
169
|
+
##### Plain Ruby
|
170
|
+
|
171
|
+
```ruby
|
172
|
+
include SpaceShipMotor
|
173
|
+
```
|
174
|
+
|
175
|
+
##### Spaces Are Ok
|
176
|
+
|
177
|
+
```ruby
|
178
|
+
include space_module("Space ship motor")
|
179
|
+
```
|
180
|
+
|
181
|
+
##### Spaces Are Ok shorthand
|
182
|
+
|
183
|
+
```ruby
|
184
|
+
include ɱ("Space ship motor")
|
185
|
+
```
|
186
|
+
|
187
|
+
#### Defining a method
|
188
|
+
|
189
|
+
##### Plain Ruby
|
190
|
+
|
191
|
+
```ruby
|
192
|
+
def travel_to_a_planet(planet)
|
193
|
+
# Method body
|
194
|
+
end
|
195
|
+
```
|
196
|
+
|
197
|
+
##### Spaces Are Ok
|
198
|
+
|
199
|
+
```ruby
|
200
|
+
space_method_def("Travel to a planet"), def _(planet)
|
201
|
+
# Method body
|
202
|
+
end
|
203
|
+
```
|
204
|
+
|
205
|
+
##### Spaces Are Ok shorthand
|
206
|
+
|
207
|
+
```ruby
|
208
|
+
∂ƒ("Travel to a planet"), def_(planet)
|
209
|
+
# Method body
|
210
|
+
end
|
211
|
+
```
|
212
|
+
|
213
|
+
#### Calling a method
|
214
|
+
|
215
|
+
##### Plain Ruby
|
216
|
+
|
217
|
+
```ruby
|
218
|
+
travel_to_a_planet(planet)
|
219
|
+
```
|
220
|
+
|
221
|
+
##### Spaces Are Ok
|
222
|
+
|
223
|
+
```ruby
|
224
|
+
space_method("Travel to a planet", planet)
|
225
|
+
```
|
226
|
+
|
227
|
+
##### Spaces Are Ok shorthand
|
228
|
+
|
229
|
+
```ruby
|
230
|
+
ƒ("Travel to a planet", planet)
|
231
|
+
```
|
232
|
+
|
233
|
+
### You don't have to care about spelling
|
234
|
+
|
235
|
+
If you're the adventurous type and don't want to worry about speling everything correctly all the time, then you don't have have to. Just turn on the `dont_worry_about_spelling`-mode.
|
236
|
+
|
237
|
+
```ruby
|
238
|
+
require 'spaces_are_ok/dont_worry_about_spelling'
|
239
|
+
|
240
|
+
space_class("Greet someone") do
|
241
|
+
def initialize(name)
|
242
|
+
@name = name
|
243
|
+
end
|
244
|
+
|
245
|
+
space_method_def "Say hello", def _
|
246
|
+
"Hello, #{@name}"
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
greeter = space_class("Greeet someone").new("Kim")
|
251
|
+
greeter.space_method("Say jello") # => Hello, Kim!
|
252
|
+
```
|
253
|
+
|
254
|
+
## But should I use it?
|
255
|
+
|
256
|
+
Probably not.
|
257
|
+
|
258
|
+
## Ideas for improvement
|
259
|
+
|
260
|
+
- I haven't been able to figure out a way of doing this for variable names. I would prefer `space_variable("Number of vowels")` over `vwl_ctr`. Wouldn't you?
|
261
|
+
- Patch Ruby so we could have this as a feature in the language. It could look something like this:
|
262
|
+
|
263
|
+
```ruby
|
264
|
+
class “Weather forecast”
|
265
|
+
def ‘will it rain tomorrow?’
|
266
|
+
puts "Time will tell"
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
“Weather forecast”.new.‘will it rain tomorrow?’ # => Time will tell
|
271
|
+
```
|
272
|
+
|
273
|
+
## Contributing
|
274
|
+
|
275
|
+
1. Fork it
|
276
|
+
2. Install the dependencies (`bundle install`)
|
277
|
+
3. Create your feature branch (`git checkout -b my-new-feature`)
|
278
|
+
4. Commit your changes (`git commit -am 'Add some feature'`)
|
279
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
280
|
+
6. Run the tests (`mtest test.rb`)
|
281
|
+
7. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "spaces_are_ok/version"
|
2
|
+
require "spaces_are_ok/classes_and_modules"
|
3
|
+
require "spaces_are_ok/methods"
|
4
|
+
require "spaces_are_ok/modify_the_kernel"
|
5
|
+
|
6
|
+
module SpacesAreOk
|
7
|
+
def self.make_a_valid_name(possibly_invalid_name, separator)
|
8
|
+
name = possibly_invalid_name.gsub(%r< [^a-z0-9_] >ix) do |m|
|
9
|
+
"#{m.ord}_"
|
10
|
+
end
|
11
|
+
name.downcase
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.find_a_matching_name(prospects, name)
|
15
|
+
prospects.detect { |prospect| prospect == name }
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module SpacesAreOk::ClassesAndModules
|
2
|
+
def self.get_class(original_name, superclass = Object, &class_definition)
|
3
|
+
creator = -> { Class.new(superclass) }
|
4
|
+
define_or_get_module_or_class(
|
5
|
+
original_name,
|
6
|
+
Class,
|
7
|
+
:class_eval,
|
8
|
+
creator,
|
9
|
+
&class_definition
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.get_module(original_name, &module_definition)
|
14
|
+
creator = -> { Module.new }
|
15
|
+
define_or_get_module_or_class(
|
16
|
+
original_name,
|
17
|
+
Module,
|
18
|
+
:module_eval,
|
19
|
+
creator,
|
20
|
+
&module_definition
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def self.define_or_get_module_or_class(original_name, type, evaluator, creator, &body)
|
27
|
+
name = get_name(original_name, type)
|
28
|
+
|
29
|
+
if !Object.const_defined?(name)
|
30
|
+
Object.const_set(name, creator.call)
|
31
|
+
end
|
32
|
+
|
33
|
+
module_or_class = Object.const_get(name)
|
34
|
+
|
35
|
+
if !body.nil?
|
36
|
+
module_or_class.send(evaluator, &body)
|
37
|
+
end
|
38
|
+
|
39
|
+
module_or_class
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.get_name(original_name, type)
|
43
|
+
name = valid_class_or_module_name_from(original_name)
|
44
|
+
close_enough = closest_existing_name_for(name, type)
|
45
|
+
name = close_enough unless close_enough.nil?
|
46
|
+
name
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.closest_existing_name_for(name, type)
|
50
|
+
names = Module.constants.select do |c|
|
51
|
+
next if c.to_s == 'Config' # Get rid of RbConfig/Config warning
|
52
|
+
Module.const_get(c).is_a?(type)
|
53
|
+
end
|
54
|
+
|
55
|
+
SpacesAreOk::find_a_matching_name(names, name)
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.valid_class_or_module_name_from(original_name)
|
59
|
+
name = SpacesAreOk::make_a_valid_name(original_name, '')
|
60
|
+
name = "a_#{name}" if name.match(%r<^ [^a-z] >x)
|
61
|
+
name.capitalize
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "spaces_are_ok"
|
2
|
+
require "rubyfish"
|
3
|
+
|
4
|
+
module SpacesAreOk
|
5
|
+
def self.find_a_matching_name(prospects, name)
|
6
|
+
names = prospects.find_all do |prospect|
|
7
|
+
RubyFish::Levenshtein.distance(name, prospect) <= 3
|
8
|
+
end
|
9
|
+
|
10
|
+
names.sort_by(&:size).first
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module SpacesAreOk::Methods
|
2
|
+
def self.get_method(original_name, the_binding)
|
3
|
+
name = valid_method_name_from(original_name)
|
4
|
+
|
5
|
+
if !method_defined?(name)
|
6
|
+
close_enough = closest_method_name(name, the_binding)
|
7
|
+
if !close_enough.nil?
|
8
|
+
name = close_enough
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
name
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def self.valid_method_name_from(original_name)
|
18
|
+
name = SpacesAreOk::make_a_valid_name(original_name, '_')
|
19
|
+
name = "a_#{name}" if name.match(%r<^ [^a-z] >x)
|
20
|
+
name
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.closest_method_name(name, the_binding)
|
24
|
+
all_methods = the_binding.eval("methods") + the_binding.eval("private_methods")
|
25
|
+
SpacesAreOk::find_a_matching_name(all_methods, name)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Kernel
|
2
|
+
# Classes
|
3
|
+
def space_class(*args, &class_definition)
|
4
|
+
SpacesAreOk::ClassesAndModules.get_class(*args, &class_definition)
|
5
|
+
end
|
6
|
+
|
7
|
+
def ç(*args, &class_definition)
|
8
|
+
space_class(*args, &class_definition)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Modules
|
12
|
+
def space_module(*args, &module_definition)
|
13
|
+
SpacesAreOk::ClassesAndModules.get_module(*args, &module_definition)
|
14
|
+
end
|
15
|
+
|
16
|
+
def ɱ(*args, &class_definition)
|
17
|
+
space_module(*args, &class_definition)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Method definition
|
21
|
+
def space_method_def(original_name, actual_method_name)
|
22
|
+
new_name = SpacesAreOk::Methods.get_method(original_name, binding)
|
23
|
+
binding.eval <<-EOS
|
24
|
+
alias_method :#{new_name}, :#{actual_method_name}
|
25
|
+
EOS
|
26
|
+
end
|
27
|
+
|
28
|
+
def ∂ƒ(original_name, actual_method_name)
|
29
|
+
space_method_def(original_name, actual_method_name)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Method invocation
|
33
|
+
def space_method(original_name, *args, &block)
|
34
|
+
send(SpacesAreOk::Methods.get_method(original_name, binding), *args, &block)
|
35
|
+
end
|
36
|
+
|
37
|
+
def ƒ(original_name, *args, &block)
|
38
|
+
space_method(original_name, *args, &block)
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'spaces_are_ok/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "spaces_are_ok"
|
8
|
+
spec.version = SpacesAreOk::VERSION
|
9
|
+
spec.authors = ["Kim Ahlström"]
|
10
|
+
spec.email = ["kim.ahlstrom@gmail.com"]
|
11
|
+
spec.description = %q{Allows the use of strings as class names, module names and method names}
|
12
|
+
spec.summary = %q{Use strings as class, module and method names}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "maxitest", "~> 1.0.3"
|
24
|
+
spec.add_dependency "rubyfish", "~> 0.0.6"
|
25
|
+
end
|
data/test.rb
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
require "codeclimate-test-reporter"
|
2
|
+
CodeClimate::TestReporter.start
|
3
|
+
|
4
|
+
$: << File.expand_path('../lib', __FILE__)
|
5
|
+
require 'maxitest/autorun'
|
6
|
+
require 'spaces_are_ok'
|
7
|
+
|
8
|
+
space_class("Greet the world") do
|
9
|
+
def initialize(name)
|
10
|
+
@name = name
|
11
|
+
end
|
12
|
+
|
13
|
+
def hi
|
14
|
+
greet("Hi")
|
15
|
+
end
|
16
|
+
|
17
|
+
space_method_def "say good bye", def _
|
18
|
+
"Good bye, #{@name}"
|
19
|
+
end
|
20
|
+
|
21
|
+
space_method_def "say good afternoon", def _
|
22
|
+
"Good afternoon, #{@name}"
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def greet(greeting)
|
28
|
+
"#{greeting}, #{@name}!"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
space_class("Shout greeting", space_class("Greet the world")) do
|
33
|
+
private
|
34
|
+
|
35
|
+
def greet(greeting)
|
36
|
+
super(greeting).upcase
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
space_module("A greeter") do
|
41
|
+
def greet
|
42
|
+
"Hello!"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
space_class("I do nothing on my own") do
|
47
|
+
include space_module("A greeter")
|
48
|
+
end
|
49
|
+
|
50
|
+
class SpacesAreOkTest < Minitest::Test
|
51
|
+
def setup
|
52
|
+
require 'spaces_are_ok'
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_make_a_valid_name
|
56
|
+
assert_equal "36__228__ncc45_170145_d47_12472_12515_12531_65309_12522_12517_12483_12463_12539_12500_12459_12540_12489_", SpacesAreOk::make_a_valid_name('$_ä_ncc-1701-d/ジャン=リュック・ピカード', '_')
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_instance_method_invocation_on_classes
|
60
|
+
assert_equal "Hi, Kim!", space_class("Greet the world").new("Kim").hi
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_subclass
|
64
|
+
assert_equal "HI, KIM!", space_class("Shout greeting").new("Kim").hi
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_module
|
68
|
+
assert_equal "Hello!", space_class("I do nothing on my own").new.greet
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_method
|
72
|
+
assert_equal "Good afternoon, Kim", space_class("Greet the world").new("Kim").space_method("Say good afternoon")
|
73
|
+
assert_equal "Good bye, Kim", space_class("Greet the world").new("Kim").space_method("Say good bye")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
class SpacesAreOkAndDontWorryAboutSpellingTest < Minitest::Test
|
78
|
+
def setup
|
79
|
+
require 'spaces_are_ok/dont_worry_about_spelling'
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_misspelled_class
|
83
|
+
assert_equal space_class("Greet the world"), space_class("Kreet the vorld")
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_misspelled_module
|
87
|
+
assert_equal space_module("A greeter"), space_module("B greeter")
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_misspelled_method
|
91
|
+
assert_equal "Good afternoon, Kim", space_class("Greet the world").new("Kim").space_method("Say good afternooon")
|
92
|
+
assert_equal "Good bye, Kim", space_class("Greet the world").new("Kim").space_method("Say good buy")
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
ç("Test fancy class names", Minitest::Test) do
|
97
|
+
def self.a
|
98
|
+
"a"
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_using_the_class_name
|
102
|
+
assert_equal "a", ç("Test fancy class names").a
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
ç("Test fancy module names", Minitest::Test) do
|
107
|
+
ɱ("Module for a") do
|
108
|
+
def a
|
109
|
+
"a"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
extend ɱ("Module for a")
|
114
|
+
|
115
|
+
def test_using_the_class_name
|
116
|
+
assert_equal "a", ç("Test fancy module names").a
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
ç("Test fancy method names", Minitest::Test) do
|
121
|
+
class << self
|
122
|
+
∂ƒ "return a", def _
|
123
|
+
"a"
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_using_the_method_name
|
128
|
+
assert_equal "a", ç("Test fancy method names").ƒ("return a")
|
129
|
+
end
|
130
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spaces_are_ok
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kim Ahlström
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: maxitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.0.3
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.0.3
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubyfish
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.0.6
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.0.6
|
69
|
+
description: Allows the use of strings as class names, module names and method names
|
70
|
+
email:
|
71
|
+
- kim.ahlstrom@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".ruby-version"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- lib/spaces_are_ok.rb
|
83
|
+
- lib/spaces_are_ok/classes_and_modules.rb
|
84
|
+
- lib/spaces_are_ok/dont_worry_about_spelling.rb
|
85
|
+
- lib/spaces_are_ok/methods.rb
|
86
|
+
- lib/spaces_are_ok/modify_the_kernel.rb
|
87
|
+
- lib/spaces_are_ok/version.rb
|
88
|
+
- spaces_are_ok.gemspec
|
89
|
+
- test.rb
|
90
|
+
homepage: ''
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.2.2
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: Use strings as class, module and method names
|
114
|
+
test_files: []
|