ruby_prototype 1.2.0
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.
- data/.document +5 -0
- data/History.txt +6 -0
- data/LICENSE +20 -0
- data/Manifest.txt +6 -0
- data/README.markdown +39 -0
- data/Rakefile +24 -0
- data/VERSION +1 -0
- data/lib/ruby_prototype.rb +16 -0
- data/ruby_prototype.gemspec +49 -0
- data/test/ruby_prototype_test.rb +33 -0
- metadata +65 -0
data/.document
ADDED
data/History.txt
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Jack Danger Canty
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Ruby Prototype
|
2
|
+
|
3
|
+
Note: Only works with Ruby 1.9+
|
4
|
+
|
5
|
+
In Javascript and other prototype languages you can add a
|
6
|
+
function/method to an object like so:
|
7
|
+
|
8
|
+
obj.perform = function(){ ... stuff to do ...}
|
9
|
+
|
10
|
+
But in Ruby 1.8 there's always been a problem where a method
|
11
|
+
defined with `define_method` won't be able to take a block.
|
12
|
+
So you'd never be able to do something like this:
|
13
|
+
|
14
|
+
"my string".do_with_words = proc do |&block|
|
15
|
+
self.split(' ').each do |word|
|
16
|
+
block.call(word)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
Because the "proc do |&block|" was unsupported syntax. And blocks
|
21
|
+
never got passed automatically so block_given? would always return
|
22
|
+
false.
|
23
|
+
|
24
|
+
But Ruby 1.9 allows the "proc do |&block|" syntax so we can now make
|
25
|
+
Ruby to act as a (quasi) fully prototype language.
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
require 'rubygems'
|
30
|
+
require 'ruby_prototype'
|
31
|
+
|
32
|
+
@object.self_times_two = proc do
|
33
|
+
self * 2
|
34
|
+
end
|
35
|
+
|
36
|
+
# The above is the exact same as this, more conventional, way:
|
37
|
+
def @object.self_times_two
|
38
|
+
self * 2
|
39
|
+
end
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "ruby_prototype"
|
8
|
+
gem.summary = %Q{Provides Ruby1.9 with a method prototyping interface}
|
9
|
+
gem.description = %Q{Allows the class-oriented Ruby language to double as a simple-object prototype language (a la Javascript)}
|
10
|
+
gem.email = "gems@6brand.com"
|
11
|
+
gem.homepage = "http://github.com/JackDanger/ruby_prototype"
|
12
|
+
gem.authors = ["Jack Danger Canty"]
|
13
|
+
end
|
14
|
+
rescue LoadError
|
15
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
16
|
+
end
|
17
|
+
|
18
|
+
require 'rake/testtask'
|
19
|
+
task :test do
|
20
|
+
exec "ruby1.9 test/ruby_prototype_test.rb"
|
21
|
+
end
|
22
|
+
|
23
|
+
task :default => :test
|
24
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.2.0
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module RubyPrototype
|
2
|
+
def method_missing(method_name, *arguments, &block)
|
3
|
+
return super unless method_name.to_s =~ /=$/ &&
|
4
|
+
((1 == arguments.length) | block_given?)
|
5
|
+
|
6
|
+
(class << self; self; end).send :define_method,
|
7
|
+
method_name.to_s.chomp('='),
|
8
|
+
&block || arguments[0]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
if RUBY_VERSION.to_f < 1.9
|
13
|
+
warn "RUBY_VERSION 1.9+ required for RubyPrototype - skipping"
|
14
|
+
else
|
15
|
+
Object.send :include, RubyPrototype
|
16
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{ruby_prototype}
|
8
|
+
s.version = "1.2.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Jack Danger Canty"]
|
12
|
+
s.date = %q{2009-09-26}
|
13
|
+
s.description = %q{Allows the class-oriented Ruby language to double as a simple-object prototype language (a la Javascript)}
|
14
|
+
s.email = %q{gems@6brand.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.markdown"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"History.txt",
|
22
|
+
"LICENSE",
|
23
|
+
"Manifest.txt",
|
24
|
+
"README.markdown",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"lib/ruby_prototype.rb",
|
28
|
+
"ruby_prototype.gemspec",
|
29
|
+
"test/ruby_prototype_test.rb"
|
30
|
+
]
|
31
|
+
s.homepage = %q{http://github.com/JackDanger/ruby_prototype}
|
32
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
33
|
+
s.require_paths = ["lib"]
|
34
|
+
s.rubygems_version = %q{1.3.5}
|
35
|
+
s.summary = %q{Provides Ruby1.9 with a method prototyping interface}
|
36
|
+
s.test_files = [
|
37
|
+
"test/ruby_prototype_test.rb"
|
38
|
+
]
|
39
|
+
|
40
|
+
if s.respond_to? :specification_version then
|
41
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
42
|
+
s.specification_version = 3
|
43
|
+
|
44
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
45
|
+
else
|
46
|
+
end
|
47
|
+
else
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../lib/ruby_prototype'
|
2
|
+
|
3
|
+
[ Object,
|
4
|
+
Object.new,
|
5
|
+
Class,
|
6
|
+
(class C; self; end),
|
7
|
+
Module,
|
8
|
+
(module M; self; end),
|
9
|
+
Object.method(:send) # Even methods can have methods now
|
10
|
+
].each do |object|
|
11
|
+
|
12
|
+
begin
|
13
|
+
# we can assign a proc to the method
|
14
|
+
object.method_that_takes_block = proc do |name, &b|
|
15
|
+
print "+"
|
16
|
+
b.call(name)
|
17
|
+
end
|
18
|
+
# or simply call the /=$/ form of the method while passing a block
|
19
|
+
object.send :more_direct= do |&b|
|
20
|
+
print "+"
|
21
|
+
b.call(self)
|
22
|
+
end
|
23
|
+
|
24
|
+
object.method_that_takes_block 'some value' do |*args|
|
25
|
+
print '+'
|
26
|
+
end
|
27
|
+
object.more_direct {|same_object| print '+'}
|
28
|
+
|
29
|
+
puts " works on #{object}"
|
30
|
+
rescue => e
|
31
|
+
puts " fails on #{object} with #{e.inspect}"
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby_prototype
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jack Danger Canty
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-09-26 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Allows the class-oriented Ruby language to double as a simple-object prototype language (a la Javascript)
|
17
|
+
email: gems@6brand.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE
|
24
|
+
- README.markdown
|
25
|
+
files:
|
26
|
+
- .document
|
27
|
+
- History.txt
|
28
|
+
- LICENSE
|
29
|
+
- Manifest.txt
|
30
|
+
- README.markdown
|
31
|
+
- Rakefile
|
32
|
+
- VERSION
|
33
|
+
- lib/ruby_prototype.rb
|
34
|
+
- ruby_prototype.gemspec
|
35
|
+
- test/ruby_prototype_test.rb
|
36
|
+
has_rdoc: true
|
37
|
+
homepage: http://github.com/JackDanger/ruby_prototype
|
38
|
+
licenses: []
|
39
|
+
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options:
|
42
|
+
- --charset=UTF-8
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: "0"
|
50
|
+
version:
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
version:
|
57
|
+
requirements: []
|
58
|
+
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 1.3.5
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: Provides Ruby1.9 with a method prototyping interface
|
64
|
+
test_files:
|
65
|
+
- test/ruby_prototype_test.rb
|