pythonism 0.0.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.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pythonism.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 USAMI Kenta
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.
@@ -0,0 +1,30 @@
1
+ Pythonism gem
2
+ =============
3
+
4
+ Ruby for my dear Pythonistas...
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'pythonism'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install pythonism
19
+
20
+ ## Usage
21
+
22
+ TODO: Write usage instructions here
23
+
24
+ ## Contributing
25
+
26
+ 1. Fork it
27
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
28
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
29
+ 4. Push to the branch (`git push origin my-new-feature`)
30
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,7 @@
1
+ require 'pythonism/version'
2
+ require 'pythonism/pythonize'
3
+ require 'pythonism/classes'
4
+ require 'pythonism/methods'
5
+
6
+ # Namespace for Pythonism
7
+ module Pythonism; end
@@ -0,0 +1,5 @@
1
+ require 'pythonism/classes/class'
2
+ require 'pythonism/classes/boolean'
3
+ require 'pythonism/classes/string'
4
+ require 'pythonism/classes/fixnum'
5
+ require 'pythonism/classes/array'
@@ -0,0 +1,17 @@
1
+ # Pythonized +String+ class
2
+ class String
3
+ include Pythonism::Pythonize::Basic
4
+
5
+ # @return [Boolean]
6
+ def __nonzero__
7
+ self.size != 0
8
+ end
9
+
10
+ # @return [Array]
11
+ def to_a
12
+ self
13
+ end
14
+
15
+ # @return [String]
16
+ def self.to_s; 'list'; end
17
+ end
@@ -0,0 +1,2 @@
1
+ require 'pythonism/classes/true_class'
2
+ require 'pythonism/classes/false_class'
@@ -0,0 +1,12 @@
1
+ # Pythonized +Class+ class
2
+ class Class
3
+ # @return [String]
4
+ def inspect
5
+ "<type '#{self.class}'>"
6
+ end
7
+
8
+ # @return [String]
9
+ def to_s
10
+ 'type'
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ # Alias of +false+ object
2
+ False = false
3
+
4
+ # Pythonized +FalseClass+ class
5
+ class FalseClass
6
+ include Pythonism::Pythonize::Basic
7
+
8
+ # @return [String]
9
+ def inspect; 'False'; end
10
+
11
+ # @return [FalseClass]
12
+ def __nonzero__; false; end
13
+
14
+ # @return [String]
15
+ def self.to_s; 'bool'; end
16
+ end
@@ -0,0 +1,13 @@
1
+ # Pythonized +Fixnum+ class
2
+ class Fixnum
3
+ include Pythonism::Pythonize::Basic
4
+ include Pythonism::Pythonize::Numeric
5
+
6
+ # @return [Boolean]
7
+ def __nonzero__
8
+ self != 0
9
+ end
10
+
11
+ # @return [String]
12
+ def self.to_s; 'int'; end
13
+ end
@@ -0,0 +1,16 @@
1
+ # Alias of +nil+ object
2
+ None = nil
3
+
4
+ # Pythonized +NilClass+ class
5
+ class NilClass
6
+ include Pythonism::Pythonize::Basic
7
+
8
+ # @return [String]
9
+ def inspect; 'False'; end
10
+
11
+ # @return [FalseClass]
12
+ def __nonzero__; false; end
13
+
14
+ # @return [String]
15
+ def self.to_s; 'bool'; end
16
+ end
@@ -0,0 +1,4 @@
1
+ # Pythonized +Object+ class
2
+ class Object
3
+ include Pythonism::Pythonize::Basic
4
+ end
@@ -0,0 +1,21 @@
1
+ # Pythonized +String+ class
2
+ class String
3
+ include Pythonism::Pythonize::Basic
4
+ include Pythonism::Pythonize::Numeric
5
+
6
+ alias startswith start_with?
7
+ alias endswith end_with?
8
+
9
+ # @return [Boolean]
10
+ def __nonzero__
11
+ self.size != 0
12
+ end
13
+
14
+ # @return [Array]
15
+ def to_a
16
+ self.each_char.to_a
17
+ end
18
+
19
+ # @return [String]
20
+ def self.to_s; 'str'; end
21
+ end
@@ -0,0 +1,13 @@
1
+ # Alias of +true+ object
2
+ True = true
3
+
4
+ # Pythonized +TrueClass+ class
5
+ class TrueClass
6
+ include Pythonism::Pythonize::Basic
7
+
8
+ # @return [String]
9
+ def inspect; 'True'; end
10
+
11
+ # @return [String]
12
+ def self.to_s; 'bool'; end
13
+ end
@@ -0,0 +1 @@
1
+ require 'pythonism/methods/kernel'
@@ -0,0 +1,55 @@
1
+ # Define Kernel methods
2
+ module ::Kernel
3
+ # @return [Object]
4
+ def this
5
+ self
6
+ end
7
+
8
+ # @param [Object] obj
9
+ # @return [Boolean]
10
+ def bool (obj)
11
+ obj.__nonzero__
12
+ end
13
+
14
+ # @param [Object] obj
15
+ # @return [Class]
16
+ def type (obj)
17
+ obj.__class__
18
+ end
19
+
20
+ # @param [Object] obj
21
+ # @return [Array]
22
+ def list (obj)
23
+ obj.to_a
24
+ end
25
+
26
+ # @param [Object] obj
27
+ # @return [Fixnum,Bignum]
28
+ def int (obj)
29
+ obj.__int__
30
+ end
31
+
32
+ # @param [Object] obj
33
+ # @return [Fixnum,Bignum]
34
+ def long (obj)
35
+ obj.__long__
36
+ end
37
+
38
+ # @param [Object] obj
39
+ # @return [Float]
40
+ def float (obj)
41
+ obj.__float__
42
+ end
43
+
44
+ # @param [Object] obj
45
+ # @return [String]
46
+ def str (obj)
47
+ obj.__str__
48
+ end
49
+
50
+ # @param [Object] obj
51
+ # @return [String]
52
+ def oct (obj)
53
+ obj.__oct__
54
+ end
55
+ end
@@ -0,0 +1,10 @@
1
+ require 'pythonism/pythonize/basic'
2
+ require 'pythonism/pythonize/numeric'
3
+
4
+ module Pythonism
5
+ # Provide Python like methods
6
+ module Pythonize; end
7
+ end
8
+
9
+ require 'pythonism/pythonize/statement'
10
+ include Pythonism::Pythonize::Statement
@@ -0,0 +1,69 @@
1
+ module Pythonism::Pythonize
2
+ # Provide Basic methods
3
+ module Basic
4
+ # @return [Object]
5
+ def __new__ (object)
6
+ raise TypeError
7
+ end
8
+
9
+ # @return [String]
10
+ def __str__
11
+ self.to_s
12
+ end
13
+
14
+ # @return [String]
15
+ def __repr__
16
+ self.inspect
17
+ end
18
+
19
+ # @return [Array]
20
+ def __list__
21
+ self.to_a
22
+ end
23
+
24
+ # @return [Class]
25
+ def __class__
26
+ self.send(:class)
27
+ end
28
+
29
+ # @return [Boolean]
30
+ def __lt__ (other)
31
+ self < other
32
+ end
33
+
34
+ # @return [Boolean]
35
+ def __le__ (other)
36
+ self <= other
37
+ end
38
+
39
+ # @return [Boolean]
40
+ def __eq__ (other)
41
+ self == other
42
+ end
43
+
44
+ # @return [Boolean]
45
+ def __gt__ (other)
46
+ self > other
47
+ end
48
+
49
+ # @return [Boolean]
50
+ def __ge__ (other)
51
+ self >= other
52
+ end
53
+
54
+ # @return [Fixnum]
55
+ def __cmp__ (other)
56
+ self <=> other
57
+ end
58
+
59
+ # @return [Boolean]
60
+ def __ne__ (other)
61
+ not self.__eq__(other)
62
+ end
63
+
64
+ # @return [Boolean]
65
+ def __nonzero__
66
+ true
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,65 @@
1
+ module Pythonism::Pythonize
2
+ # Provide Numeric methods
3
+ module Numeric
4
+
5
+ # @return [Fixnum,Bignum]
6
+ def __int__
7
+ self.to_i
8
+ end
9
+
10
+ # @return [Fixnum,Bignum]
11
+ def __long__
12
+ self.to_i
13
+ end
14
+
15
+ # @return [Float]
16
+ def __float__
17
+ self.to_f
18
+ end
19
+
20
+ # @return [String]
21
+ def __oct__
22
+ '%o' % self.__int__
23
+ end
24
+
25
+ # @return [String]
26
+ def __hex__
27
+ '%x' % self.__int__
28
+ end
29
+
30
+ # @return [Object]
31
+ def __add__ (other)
32
+ self + other
33
+ end
34
+
35
+ # @return [Object]
36
+ def __sub__ (other)
37
+ self - other
38
+ end
39
+
40
+ # @return [Object]
41
+ def __mul__ (other)
42
+ self * other
43
+ end
44
+
45
+ # @return [Object]
46
+ def __mod__(other)
47
+ self % other
48
+ end
49
+
50
+ # @return [Object]
51
+ def __and__(other)
52
+ self & other
53
+ end
54
+
55
+ # @return [Object]
56
+ def __xor__(other)
57
+ self ^ other
58
+ end
59
+
60
+ # @return [Object]
61
+ def __or__(other)
62
+ self | other
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,33 @@
1
+ module Pythonism::Pythonize::Statement
2
+ def import (obj)
3
+ case obj.inspect
4
+ when 'main'
5
+ puts <<EOT
6
+ The Zen of Python, by Tim Peters
7
+
8
+ Beautiful is better than ugly.
9
+ Explicit is better than implicit.
10
+ Simple is better than complex.
11
+ Complex is better than complicated.
12
+ Flat is better than nested.
13
+ Sparse is better than dense.
14
+ Readability counts.
15
+ Special cases aren't special enough to break the rules.
16
+ Although practicality beats purity.
17
+ Errors should never pass silently.
18
+ Unless explicitly silenced.
19
+ In the face of ambiguity, refuse the temptation to guess.
20
+ There should be one-- and preferably only one --obvious way to do it.
21
+ Although that way may not be obvious at first unless you're Dutch.
22
+ Now is better than never.
23
+ Although never is often better than *right* now.
24
+ If the implementation is hard to explain, it's a bad idea.
25
+ If the implementation is easy to explain, it may be a good idea.
26
+ Namespaces are one honking great idea -- let's do more of those!
27
+ EOT
28
+ nil
29
+ else
30
+ require obj.to_s
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module Pythonism
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pythonism/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "pythonism"
8
+ gem.version = Pythonism::VERSION
9
+ gem.authors = ["USAMI Kenta"]
10
+ gem.email = ["tadsan@zonu.me"]
11
+ gem.description = "This gem was made for friendship with Pythonistas."
12
+ gem.summary = <<EOT
13
+ Pythonism gem provides Python-like interface and functions.
14
+
15
+ We are convinced that you should come to like Ruby if you do not like Ruby.
16
+ We are convinced that you should come to like Python if you do not like Python.
17
+
18
+ But, we have not a plan of perfect python emulation in the future either.
19
+
20
+ I say honestly, but this is a joke gem.
21
+ EOT
22
+ gem.homepage = "http://dt.zonu.me/"
23
+
24
+ gem.files = `git ls-files`.split($/)
25
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
26
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
27
+ gem.require_paths = %w(lib)
28
+ end
@@ -0,0 +1,14 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ describe Array do
4
+ context '' do
5
+ let(:ary){ [1, 2, 3] }
6
+ it{ expect( bool(ary) ).to be_true }
7
+ it{ expect( list(ary) ).to eq ary }
8
+ end
9
+ context 'empty' do
10
+ let(:ary){ [] }
11
+ it{ expect( bool(ary) ).to be_false }
12
+ it{ expect( list(ary) ).to eq ary }
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ describe Fixnum do
4
+ context 'non-zero number' do
5
+ let(:num){ 1 }
6
+ it{ expect( bool(num) ).to be_true }
7
+ it{ expect( int(num) ).to eq num }
8
+ end
9
+ context 'zero' do
10
+ let(:num){ 0 }
11
+ it{ expect( bool(num) ).to be_false }
12
+ it{ expect( int(num) ).to eq num }
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ describe String do
4
+ context 'string' do
5
+ let(:str){ 'str' }
6
+ it{ expect( bool(str) ).to be_true }
7
+ it{ expect( list(str) ).to eq str.each_char.to_a }
8
+ end
9
+ context 'empty string' do
10
+ let(:str){ '' }
11
+ it{ expect( bool(str) ).to be_false }
12
+ it{ expect( list(str) ).to eq str.each_char.to_a }
13
+ end
14
+ end
@@ -0,0 +1,6 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ describe Pythonism do
4
+ it{ expect(Pythonism::VERSION).to be_an_instance_of String }
5
+ it{ Pythonism::VERSION.should be =~ /\n{1,2}\.\n{1,2}\.\n{1,2}/ }
6
+ end
@@ -0,0 +1,6 @@
1
+ require 'rspec'
2
+
3
+ lib = File.expand_path('../../lib', __FILE__)
4
+ $:.unshift(lib)
5
+
6
+ require 'pythonism'
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pythonism
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - USAMI Kenta
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-14 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: This gem was made for friendship with Pythonistas.
15
+ email:
16
+ - tadsan@zonu.me
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - lib/pythonism.rb
27
+ - lib/pythonism/classes.rb
28
+ - lib/pythonism/classes/array.rb
29
+ - lib/pythonism/classes/boolean.rb
30
+ - lib/pythonism/classes/class.rb
31
+ - lib/pythonism/classes/false_class.rb
32
+ - lib/pythonism/classes/fixnum.rb
33
+ - lib/pythonism/classes/nil_class.rb
34
+ - lib/pythonism/classes/object.rb
35
+ - lib/pythonism/classes/string.rb
36
+ - lib/pythonism/classes/true_class.rb
37
+ - lib/pythonism/methods.rb
38
+ - lib/pythonism/methods/kernel.rb
39
+ - lib/pythonism/pythonize.rb
40
+ - lib/pythonism/pythonize/basic.rb
41
+ - lib/pythonism/pythonize/numeric.rb
42
+ - lib/pythonism/pythonize/statement.rb
43
+ - lib/pythonism/version.rb
44
+ - pythonism.gemspec
45
+ - spec/pythonism/classes/array_spec.rb
46
+ - spec/pythonism/classes/fixnum_spec.rb
47
+ - spec/pythonism/classes/string_spec.rb
48
+ - spec/pythonism_spec.rb
49
+ - spec/spec_helper.rb
50
+ homepage: http://dt.zonu.me/
51
+ licenses: []
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubyforge_project:
70
+ rubygems_version: 1.8.23
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: Pythonism gem provides Python-like interface and functions. We are convinced
74
+ that you should come to like Ruby if you do not like Ruby. We are convinced that
75
+ you should come to like Python if you do not like Python. But, we have not a plan
76
+ of perfect python emulation in the future either. I say honestly, but this is a
77
+ joke gem.
78
+ test_files:
79
+ - spec/pythonism/classes/array_spec.rb
80
+ - spec/pythonism/classes/fixnum_spec.rb
81
+ - spec/pythonism/classes/string_spec.rb
82
+ - spec/pythonism_spec.rb
83
+ - spec/spec_helper.rb
84
+ has_rdoc: