pythonism 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rubocop.yml +10 -0
- data/LICENSE.txt +2 -2
- data/lib/pythonism.rb +6 -5
- data/lib/pythonism/classes/array.rb +5 -3
- data/lib/pythonism/classes/false_class.rb +9 -3
- data/lib/pythonism/classes/string.rb +5 -3
- data/lib/pythonism/classes/true_class.rb +6 -2
- data/lib/pythonism/functions.rb +4 -4
- data/lib/pythonism/functions/builtin.rb +9 -9
- data/lib/pythonism/pythonize/basic.rb +13 -13
- data/lib/pythonism/pythonize/numeric.rb +48 -52
- data/lib/pythonism/pythonize/statement.rb +2 -2
- data/lib/pythonism/version.rb +1 -1
- data/pythonism.gemspec +1 -1
- data/spec/pythonism/classes/array_spec.rb +2 -2
- data/spec/pythonism/classes/fixnum_spec.rb +2 -2
- data/spec/pythonism/classes/string_spec.rb +2 -2
- data/spec/pythonism_spec.rb +1 -1
- metadata +11 -14
- data/bin/pythonism +0 -2
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3318a87e3e312a3e3d445aafcad430871de0e22c
|
4
|
+
data.tar.gz: be49c88777c98b6fe64e1516c6a8efdbc8cb8353
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 34217c27544a3a18f9ef37f38cafc5b540bf7e5dd6b527b9031593a17a9ccb0c5e1defd263448e3cab067ee61bf771b45df8de88581f10f66c40ee751321d145
|
7
|
+
data.tar.gz: 3ce6b7a039d12f82f8a24d856a79c0a70eb60ecc6c30b8f16e8706e1676eb5abb778eeca4f40145e4d23f0a30cd8c6a4e519f66a23a93f56001c578e833d057e
|
data/.rubocop.yml
ADDED
data/LICENSE.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c)
|
1
|
+
Copyright (c) 2016 USAMI Kenta
|
2
2
|
|
3
3
|
MIT License
|
4
4
|
|
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
19
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
20
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
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.
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/pythonism.rb
CHANGED
@@ -1,10 +1,7 @@
|
|
1
|
-
require 'pythonism/version'
|
2
|
-
require 'pythonism/pythonize'
|
3
|
-
require 'pythonism/classes'
|
4
|
-
require 'pythonism/functions'
|
5
|
-
|
6
1
|
# Namespace for Pythonism
|
7
2
|
module Pythonism
|
3
|
+
autoload :VERSION, 'pythonism/version'
|
4
|
+
|
8
5
|
# Zen of Python
|
9
6
|
# @author Tim Peters
|
10
7
|
# @see http://www.python.org/dev/peps/pep-0020/
|
@@ -33,3 +30,7 @@ If the implementation is easy to explain, it may be a good idea.
|
|
33
30
|
Namespaces are one honking great idea -- let's do more of those!
|
34
31
|
EOT
|
35
32
|
end
|
33
|
+
|
34
|
+
require 'pythonism/pythonize'
|
35
|
+
require 'pythonism/classes'
|
36
|
+
require 'pythonism/functions'
|
@@ -4,7 +4,7 @@ class Array
|
|
4
4
|
|
5
5
|
# @return [Boolean]
|
6
6
|
def __nonzero__
|
7
|
-
|
7
|
+
size != 0
|
8
8
|
end
|
9
9
|
|
10
10
|
# @return [Array]
|
@@ -14,9 +14,11 @@ class Array
|
|
14
14
|
|
15
15
|
# @return [String]
|
16
16
|
def to_s
|
17
|
-
"[#{
|
17
|
+
"[#{join(', ')}]"
|
18
18
|
end
|
19
19
|
|
20
20
|
# @return [String]
|
21
|
-
def self.to_s
|
21
|
+
def self.to_s
|
22
|
+
'list'
|
23
|
+
end
|
22
24
|
end
|
@@ -6,11 +6,17 @@ class FalseClass
|
|
6
6
|
include Pythonism::Pythonize::Basic
|
7
7
|
|
8
8
|
# @return [String]
|
9
|
-
def inspect
|
9
|
+
def inspect
|
10
|
+
'False'
|
11
|
+
end
|
10
12
|
|
11
13
|
# @return [FalseClass]
|
12
|
-
def __nonzero__
|
14
|
+
def __nonzero__
|
15
|
+
false
|
16
|
+
end
|
13
17
|
|
14
18
|
# @return [String]
|
15
|
-
def self.to_s
|
19
|
+
def self.to_s
|
20
|
+
'bool'
|
21
|
+
end
|
16
22
|
end
|
@@ -8,14 +8,16 @@ class String
|
|
8
8
|
|
9
9
|
# @return [Boolean]
|
10
10
|
def __nonzero__
|
11
|
-
|
11
|
+
size != 0
|
12
12
|
end
|
13
13
|
|
14
14
|
# @return [Array]
|
15
15
|
def to_a
|
16
|
-
|
16
|
+
each_char.to_a
|
17
17
|
end
|
18
18
|
|
19
19
|
# @return [String]
|
20
|
-
def self.to_s
|
20
|
+
def self.to_s
|
21
|
+
'str'
|
22
|
+
end
|
21
23
|
end
|
data/lib/pythonism/functions.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# Provide Python like functions
|
2
2
|
module Pythonism::Functions
|
3
|
-
#
|
4
3
|
IMPORT_PROCS = {
|
5
|
-
builtin: proc{ include Pythonism::Functions::Builtin },
|
4
|
+
builtin: proc { include Pythonism::Functions::Builtin },
|
6
5
|
}
|
7
6
|
|
8
7
|
# @param [Symbol]
|
9
|
-
def self.import
|
8
|
+
def self.import(key)
|
10
9
|
::Object.class_eval(&IMPORT_PROCS[key.to_sym])
|
11
10
|
end
|
12
11
|
end
|
12
|
+
|
13
13
|
require 'pythonism/functions/builtin'
|
14
|
-
Pythonism::Functions
|
14
|
+
Pythonism::Functions.import(:builtin)
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Pythonism::Functions::Builtin
|
4
4
|
# @param [Object] obj
|
5
5
|
# @return [Boolean,Method]
|
6
|
-
def bool
|
6
|
+
def bool(*obj)
|
7
7
|
case obj.size
|
8
8
|
when 0
|
9
9
|
method(:bool)
|
@@ -16,7 +16,7 @@ module Pythonism::Functions::Builtin
|
|
16
16
|
|
17
17
|
# @param [Object] obj
|
18
18
|
# @return [Class]
|
19
|
-
def type
|
19
|
+
def type(*obj)
|
20
20
|
case obj.size
|
21
21
|
when 0
|
22
22
|
Class
|
@@ -29,7 +29,7 @@ module Pythonism::Functions::Builtin
|
|
29
29
|
|
30
30
|
# @param [Object] obj
|
31
31
|
# @return [Array,Class]
|
32
|
-
def list
|
32
|
+
def list(*obj)
|
33
33
|
case obj.size
|
34
34
|
when 0
|
35
35
|
Array
|
@@ -42,7 +42,7 @@ module Pythonism::Functions::Builtin
|
|
42
42
|
|
43
43
|
# @param [Object] obj
|
44
44
|
# @return [Fixnum,Bignum,Class]
|
45
|
-
def int
|
45
|
+
def int(*obj)
|
46
46
|
case obj.size
|
47
47
|
when 0
|
48
48
|
Fixnum
|
@@ -55,7 +55,7 @@ module Pythonism::Functions::Builtin
|
|
55
55
|
|
56
56
|
# @param [Object] obj
|
57
57
|
# @return [Fixnum,Bignum,Class]
|
58
|
-
def long
|
58
|
+
def long(*obj)
|
59
59
|
case obj.size
|
60
60
|
when 0
|
61
61
|
Bignum
|
@@ -68,7 +68,7 @@ module Pythonism::Functions::Builtin
|
|
68
68
|
|
69
69
|
# @param [Object] obj
|
70
70
|
# @return [Float,Class]
|
71
|
-
def float
|
71
|
+
def float(*obj)
|
72
72
|
case obj.size
|
73
73
|
when 0
|
74
74
|
Float
|
@@ -81,7 +81,7 @@ module Pythonism::Functions::Builtin
|
|
81
81
|
|
82
82
|
# @param [Object] obj
|
83
83
|
# @return [String,Class]
|
84
|
-
def str
|
84
|
+
def str(*obj)
|
85
85
|
case obj.size
|
86
86
|
when 0
|
87
87
|
String
|
@@ -92,7 +92,7 @@ module Pythonism::Functions::Builtin
|
|
92
92
|
|
93
93
|
# @param [Object] obj
|
94
94
|
# @return [String,Class]
|
95
|
-
def hex
|
95
|
+
def hex(*obj)
|
96
96
|
case obj.size
|
97
97
|
when 0
|
98
98
|
method(:hex)
|
@@ -105,7 +105,7 @@ module Pythonism::Functions::Builtin
|
|
105
105
|
|
106
106
|
# @param [Object] obj
|
107
107
|
# @return [String,Class]
|
108
|
-
def oct
|
108
|
+
def oct(*obj)
|
109
109
|
case obj.size
|
110
110
|
when 0
|
111
111
|
method(:oct)
|
@@ -2,63 +2,63 @@ module Pythonism::Pythonize
|
|
2
2
|
# Provide Basic methods
|
3
3
|
module Basic
|
4
4
|
# @return [Object]
|
5
|
-
def __new__
|
5
|
+
def __new__(_object)
|
6
6
|
raise TypeError
|
7
7
|
end
|
8
8
|
|
9
9
|
# @return [String]
|
10
10
|
def __str__
|
11
|
-
|
11
|
+
to_s
|
12
12
|
end
|
13
13
|
|
14
14
|
# @return [String]
|
15
15
|
def __repr__
|
16
|
-
|
16
|
+
inspect
|
17
17
|
end
|
18
18
|
|
19
19
|
# @return [Array]
|
20
20
|
def __list__
|
21
|
-
|
21
|
+
to_a
|
22
22
|
end
|
23
23
|
|
24
24
|
# @return [Class]
|
25
25
|
def __class__
|
26
|
-
self.
|
26
|
+
self.class
|
27
27
|
end
|
28
28
|
|
29
29
|
# @return [Boolean]
|
30
|
-
def __lt__
|
30
|
+
def __lt__(other)
|
31
31
|
self < other
|
32
32
|
end
|
33
33
|
|
34
34
|
# @return [Boolean]
|
35
|
-
def __le__
|
35
|
+
def __le__(other)
|
36
36
|
self <= other
|
37
37
|
end
|
38
38
|
|
39
39
|
# @return [Boolean]
|
40
|
-
def __eq__
|
40
|
+
def __eq__(other)
|
41
41
|
self == other
|
42
42
|
end
|
43
43
|
|
44
44
|
# @return [Boolean]
|
45
|
-
def __gt__
|
45
|
+
def __gt__(other)
|
46
46
|
self > other
|
47
47
|
end
|
48
48
|
|
49
49
|
# @return [Boolean]
|
50
|
-
def __ge__
|
50
|
+
def __ge__(other)
|
51
51
|
self >= other
|
52
52
|
end
|
53
53
|
|
54
54
|
# @return [Fixnum]
|
55
|
-
def __cmp__
|
55
|
+
def __cmp__(other)
|
56
56
|
self <=> other
|
57
57
|
end
|
58
58
|
|
59
59
|
# @return [Boolean]
|
60
|
-
def __ne__
|
61
|
-
|
60
|
+
def __ne__(other)
|
61
|
+
self != (other)
|
62
62
|
end
|
63
63
|
|
64
64
|
# @return [Boolean]
|
@@ -1,65 +1,61 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
def __int__
|
7
|
-
self.to_i
|
8
|
-
end
|
1
|
+
# Provide Numeric methods
|
2
|
+
module Pythonism::Pythonize::Numeric
|
3
|
+
def __int__
|
4
|
+
to_i
|
5
|
+
end
|
9
6
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
# @return [Integer]
|
8
|
+
def __long__
|
9
|
+
to_i
|
10
|
+
end
|
14
11
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
# @return [Float]
|
13
|
+
def __float__
|
14
|
+
to_f
|
15
|
+
end
|
19
16
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
# @return [String]
|
18
|
+
def __oct__
|
19
|
+
format('%o', __int__)
|
20
|
+
end
|
24
21
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
22
|
+
# @return [String]
|
23
|
+
def __hex__
|
24
|
+
format('%x', __int__)
|
25
|
+
end
|
29
26
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
# @return [Object]
|
28
|
+
def __add__(other)
|
29
|
+
self + other
|
30
|
+
end
|
34
31
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
32
|
+
# @return [Object]
|
33
|
+
def __sub__(other)
|
34
|
+
self - other
|
35
|
+
end
|
39
36
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
37
|
+
# @return [Object]
|
38
|
+
def __mul__(other)
|
39
|
+
self * other
|
40
|
+
end
|
44
41
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
42
|
+
# @return [Object]
|
43
|
+
def __mod__(other)
|
44
|
+
self % other
|
45
|
+
end
|
49
46
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
47
|
+
# @return [Object]
|
48
|
+
def __and__(other)
|
49
|
+
self & other
|
50
|
+
end
|
54
51
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
52
|
+
# @return [Object]
|
53
|
+
def __xor__(other)
|
54
|
+
self ^ other
|
55
|
+
end
|
59
56
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
end
|
57
|
+
# @return [Object]
|
58
|
+
def __or__(other)
|
59
|
+
self | other
|
64
60
|
end
|
65
61
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
module Pythonism::Pythonize::Statement
|
3
3
|
# method of imitation +import+ statement
|
4
4
|
# @return [Boolean]
|
5
|
-
def import
|
5
|
+
def import(obj)
|
6
6
|
case obj
|
7
7
|
when :this
|
8
8
|
puts Pythonism::ZEN_OF_PYTHON
|
@@ -15,7 +15,7 @@ module Pythonism::Pythonize::Statement
|
|
15
15
|
# special keyword for Zen
|
16
16
|
# @return [Symbol]
|
17
17
|
def this
|
18
|
-
case
|
18
|
+
case inspect
|
19
19
|
when 'main'
|
20
20
|
:this
|
21
21
|
else
|
data/lib/pythonism/version.rb
CHANGED
data/pythonism.gemspec
CHANGED
@@ -19,7 +19,7 @@ But, we have not a plan of perfect python emulation in the future either.
|
|
19
19
|
|
20
20
|
I say honestly, but this is a joke gem.
|
21
21
|
EOT
|
22
|
-
gem.homepage =
|
22
|
+
gem.homepage = 'http://tadsan.github.io/'
|
23
23
|
|
24
24
|
gem.files = `git ls-files`.split($/)
|
25
25
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
@@ -5,14 +5,14 @@ describe Array do
|
|
5
5
|
let(:ary){ [1, 2, 3] }
|
6
6
|
it{ expect( ary ).to be_an_instance_of list }
|
7
7
|
it{ expect( str(ary) ).to eq '[1, 2, 3]' }
|
8
|
-
it{ expect( bool(ary) ).to
|
8
|
+
it{ expect( bool(ary) ).to be true }
|
9
9
|
it{ expect( list(ary) ).to eq ary }
|
10
10
|
end
|
11
11
|
context 'empty' do
|
12
12
|
let(:ary){ [] }
|
13
13
|
it{ expect( ary ).to be_an_instance_of list }
|
14
14
|
it{ expect( str(ary) ).to eq '[]' }
|
15
|
-
it{ expect( bool(ary) ).to
|
15
|
+
it{ expect( bool(ary) ).to be false }
|
16
16
|
it{ expect( list(ary) ).to eq ary }
|
17
17
|
end
|
18
18
|
end
|
@@ -5,7 +5,7 @@ describe Fixnum do
|
|
5
5
|
let(:num){ 1 }
|
6
6
|
it{ expect( num ).to be_an_instance_of int }
|
7
7
|
it{ expect( type(num) ).to eq int }
|
8
|
-
it{ expect( bool(num) ).to
|
8
|
+
it{ expect( bool(num) ).to be true }
|
9
9
|
it{ expect( int(num) ).to eq num }
|
10
10
|
it{ expect( str(num) ).to eq '1' }
|
11
11
|
end
|
@@ -13,7 +13,7 @@ describe Fixnum do
|
|
13
13
|
let(:num){ 0 }
|
14
14
|
it{ expect( num ).to be_an_instance_of int }
|
15
15
|
it{ expect( type(num) ).to eq int }
|
16
|
-
it{ expect( bool(num) ).to
|
16
|
+
it{ expect( bool(num) ).to be false }
|
17
17
|
it{ expect( int(num) ).to eq num }
|
18
18
|
it{ expect( str(num) ).to eq '0' }
|
19
19
|
end
|
@@ -5,14 +5,14 @@ describe String do
|
|
5
5
|
let(:string){ 'str' }
|
6
6
|
it{ expect( string ).to be_an_instance_of str }
|
7
7
|
it{ expect( type(string) ).to eq str }
|
8
|
-
it{ expect( bool(string) ).to
|
8
|
+
it{ expect( bool(string) ).to be true }
|
9
9
|
it{ expect( list(string) ).to eq string.each_char.to_a }
|
10
10
|
end
|
11
11
|
context 'empty string' do
|
12
12
|
let(:string){ '' }
|
13
13
|
it{ expect( string ).to be_an_instance_of str }
|
14
14
|
it{ expect( type(string) ).to eq str }
|
15
|
-
it{ expect( bool(string) ).to
|
15
|
+
it{ expect( bool(string) ).to be false }
|
16
16
|
it{ expect( list(string) ).to eq string.each_char.to_a }
|
17
17
|
end
|
18
18
|
end
|
data/spec/pythonism_spec.rb
CHANGED
@@ -2,5 +2,5 @@ require File.expand_path('../spec_helper', __FILE__)
|
|
2
2
|
|
3
3
|
describe Pythonism do
|
4
4
|
it{ expect(Pythonism::VERSION).to be_an_instance_of String }
|
5
|
-
it{ Pythonism::VERSION.
|
5
|
+
it{ expect(Pythonism::VERSION).to be =~ /[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}/ }
|
6
6
|
end
|
metadata
CHANGED
@@ -1,30 +1,28 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pythonism
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.5
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- USAMI Kenta
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2016-02-22 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: This gem was made for friendship with Pythonistas.
|
15
14
|
email:
|
16
15
|
- tadsan@zonu.me
|
17
|
-
executables:
|
18
|
-
- pythonism
|
16
|
+
executables: []
|
19
17
|
extensions: []
|
20
18
|
extra_rdoc_files: []
|
21
19
|
files:
|
22
|
-
- .gitignore
|
20
|
+
- ".gitignore"
|
21
|
+
- ".rubocop.yml"
|
23
22
|
- Gemfile
|
24
23
|
- LICENSE.txt
|
25
24
|
- README.md
|
26
25
|
- Rakefile
|
27
|
-
- bin/pythonism
|
28
26
|
- lib/pythonism.rb
|
29
27
|
- lib/pythonism/classes.rb
|
30
28
|
- lib/pythonism/classes/array.rb
|
@@ -49,29 +47,28 @@ files:
|
|
49
47
|
- spec/pythonism/classes/string_spec.rb
|
50
48
|
- spec/pythonism_spec.rb
|
51
49
|
- spec/spec_helper.rb
|
52
|
-
homepage: http://
|
50
|
+
homepage: http://tadsan.github.io/
|
53
51
|
licenses: []
|
52
|
+
metadata: {}
|
54
53
|
post_install_message:
|
55
54
|
rdoc_options: []
|
56
55
|
require_paths:
|
57
56
|
- lib
|
58
57
|
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
-
none: false
|
60
58
|
requirements:
|
61
|
-
- -
|
59
|
+
- - ">="
|
62
60
|
- !ruby/object:Gem::Version
|
63
61
|
version: '0'
|
64
62
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
63
|
requirements:
|
67
|
-
- -
|
64
|
+
- - ">="
|
68
65
|
- !ruby/object:Gem::Version
|
69
66
|
version: '0'
|
70
67
|
requirements: []
|
71
68
|
rubyforge_project:
|
72
|
-
rubygems_version:
|
69
|
+
rubygems_version: 2.4.5
|
73
70
|
signing_key:
|
74
|
-
specification_version:
|
71
|
+
specification_version: 4
|
75
72
|
summary: Pythonism gem provides Python-like interface and functions. We are convinced
|
76
73
|
that you should come to like Ruby if you do not like Ruby. We are convinced that
|
77
74
|
you should come to like Python if you do not like Python. But, we have not a plan
|
data/bin/pythonism
DELETED