ruby-racer 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +36 -0
- data/Rakefile +2 -0
- data/lib/ruby-racer.rb +14 -0
- data/lib/ruby-racer/moods/happy.rb +14 -0
- data/lib/ruby-racer/moods/sad.rb +13 -0
- data/lib/ruby-racer/race.rb +32 -0
- data/lib/ruby-racer/racer.rb +35 -0
- data/lib/ruby-racer/timer.rb +19 -0
- data/lib/ruby-racer/version.rb +3 -0
- data/ruby-racer.gemspec +22 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1364da23e45f5bc46f109109e5110eadd1431064
|
4
|
+
data.tar.gz: e3f0f62cabf1c735753439a17ec81e74595c3213
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 820103e44af06267dd7a558681e5c5a47ca8567667c8b64447fe4eacb154dffb25fc33b249c9bda99cdd8c3293ff444fa0cd4ee4db372d66f9c639f39fa9f462
|
7
|
+
data.tar.gz: 98cd2589fb3d5298ec24faa8efb86a4c8816114f502cfc5fc5f24ee00e9f3bb764282f0d4fa10129eea4211938e48ac62613931aa0351f1297b91e72ffec943b
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2016 Danielle Adams
|
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,36 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/ruby-racer.svg)](https://badge.fury.io/rb/ruby-racer)
|
2
|
+
# RubyRacer
|
3
|
+
|
4
|
+
This gem allows you to write rewrite your Ruby methods and test them from the command line.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
$ gem install ruby-racer
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
# my_method.rb
|
14
|
+
|
15
|
+
require 'ruby-racer'
|
16
|
+
|
17
|
+
method_name = :method_name
|
18
|
+
|
19
|
+
input = [1, 2, 3]
|
20
|
+
|
21
|
+
my_method = Proc.new do |input|
|
22
|
+
# write method code here
|
23
|
+
end
|
24
|
+
|
25
|
+
RubyRacer.go(method_name, input, &my_method)
|
26
|
+
```
|
27
|
+
|
28
|
+
$ ruby my_method.rb
|
29
|
+
|
30
|
+
## Contributing
|
31
|
+
|
32
|
+
1. Fork it ( https://github.com/danielleadams/ruby-racer/fork )
|
33
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
34
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
35
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
36
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/ruby-racer.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'colorize'
|
2
|
+
require 'ruby-progressbar'
|
3
|
+
|
4
|
+
require_relative 'ruby-racer/moods/happy'
|
5
|
+
require_relative 'ruby-racer/moods/sad'
|
6
|
+
require_relative 'ruby-racer/race'
|
7
|
+
require_relative 'ruby-racer/racer'
|
8
|
+
require_relative 'ruby-racer/timer'
|
9
|
+
|
10
|
+
class RubyRacer
|
11
|
+
def self.go(method, input, &block)
|
12
|
+
::Race.start(method, input, &block)
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class Race
|
2
|
+
def self.start(method, input, &block)
|
3
|
+
pb2 = ::Racer.new('You')
|
4
|
+
pb1 = ::Racer.new('Ruby')
|
5
|
+
|
6
|
+
t2 = ::Timer.new
|
7
|
+
t1 = ::Timer.new
|
8
|
+
|
9
|
+
t2.measure_time do
|
10
|
+
pb2.race { block.call(input) }
|
11
|
+
end
|
12
|
+
|
13
|
+
t1.measure_time do
|
14
|
+
pb1.race { input.send(method) }
|
15
|
+
end
|
16
|
+
|
17
|
+
puts "\n"
|
18
|
+
|
19
|
+
puts "#{pb2.name} Race Time: #{t2.display_time}".colorize(:cyan)
|
20
|
+
puts "#{pb1.name} Race Time: #{t1.display_time}".colorize(:cyan)
|
21
|
+
|
22
|
+
puts "\n"
|
23
|
+
|
24
|
+
if t2.result_time < t1.result_time
|
25
|
+
puts 'YOU WIN'.colorize(:green) + Moods::Happy.face
|
26
|
+
else
|
27
|
+
puts 'YOU LOSE'.colorize(:red) + Moods::Sad.face
|
28
|
+
end
|
29
|
+
|
30
|
+
puts "\n\n\n\n\n\n"
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class Racer
|
2
|
+
attr_reader :name
|
3
|
+
|
4
|
+
ITERATIONS = 50000
|
5
|
+
|
6
|
+
def initialize(title)
|
7
|
+
@name = title
|
8
|
+
@progress = setup_progress_bar
|
9
|
+
end
|
10
|
+
|
11
|
+
def race
|
12
|
+
ITERATIONS.times do
|
13
|
+
yield
|
14
|
+
@progress.increment
|
15
|
+
end
|
16
|
+
@progress.reset
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def setup_progress_bar
|
22
|
+
ProgressBar.create(
|
23
|
+
:format => '%t %bᗧ%i %p%%',
|
24
|
+
:title => "#{name}".colorize(color),
|
25
|
+
:throttle_rate => 0.001,
|
26
|
+
:total => ITERATIONS,
|
27
|
+
:progress_mark => '_',
|
28
|
+
:remainder_mark => '.'
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
def color
|
33
|
+
name == 'Ruby' ? :red : [ :green, :cyan, :magenta ].sample
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class Timer
|
2
|
+
attr_reader :result_time
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@result_time = nil
|
6
|
+
end
|
7
|
+
|
8
|
+
def measure_time
|
9
|
+
begin_time = Time.now
|
10
|
+
yield
|
11
|
+
end_time = Time.now
|
12
|
+
|
13
|
+
@result_time = end_time - begin_time
|
14
|
+
end
|
15
|
+
|
16
|
+
def display_time
|
17
|
+
result_time.to_s + ' seconds'
|
18
|
+
end
|
19
|
+
end
|
data/ruby-racer.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ruby-racer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ruby-racer"
|
8
|
+
spec.version = RubyRacer::VERSION
|
9
|
+
spec.authors = ["Danielle Adams"]
|
10
|
+
spec.email = ["adamzdanielle@gmail.com"]
|
11
|
+
spec.summary = %q{Gem to challenge Ruby methods.}
|
12
|
+
spec.description = %q{Write your own Ruby methods and race them against the methods written in CRuby.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-racer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Danielle Adams
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-24 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.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Write your own Ruby methods and race them against the methods written
|
42
|
+
in CRuby.
|
43
|
+
email:
|
44
|
+
- adamzdanielle@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- lib/ruby-racer.rb
|
55
|
+
- lib/ruby-racer/moods/happy.rb
|
56
|
+
- lib/ruby-racer/moods/sad.rb
|
57
|
+
- lib/ruby-racer/race.rb
|
58
|
+
- lib/ruby-racer/racer.rb
|
59
|
+
- lib/ruby-racer/timer.rb
|
60
|
+
- lib/ruby-racer/version.rb
|
61
|
+
- ruby-racer.gemspec
|
62
|
+
homepage: ''
|
63
|
+
licenses:
|
64
|
+
- MIT
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 2.5.1
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: Gem to challenge Ruby methods.
|
86
|
+
test_files: []
|