object-send 1.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.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.markdown +17 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/lib/object/send.rb +20 -0
- data/object-send.gemspec +73 -0
- data/spec/send_spec.rb +40 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +9 -0
- metadata +106 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Kim Burgestrand
|
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/README.markdown
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
What is send?
|
2
|
+
=============
|
3
|
+
It’s a tiny wee ruby gem that is a fork of [Object#try](http://ozmm.org/posts/try.html)
|
4
|
+
and [Object#try from Rails](http://api.rubyonrails.org/classes/Object.html#M000027). It will *never* throw a NoMethodError (no matter the receiver), and returns nil
|
5
|
+
if called on a nil-class or if the method in the receiver does not exist.
|
6
|
+
|
7
|
+
Note on Patches/Pull Requests
|
8
|
+
-----------------------------
|
9
|
+
|
10
|
+
1. [Fork me!](http://github.com/Burgestrand/send-/fork)
|
11
|
+
2. Write tests for your new feature or bug fix (important, I don’t want
|
12
|
+
to break your stuff in a future update by accident!)
|
13
|
+
3. Hack away on the code; make your tests pass.
|
14
|
+
4. Commit! Don’t touch Rakefile, version or git history in any of the
|
15
|
+
commits you want me to pick.
|
16
|
+
5. ???
|
17
|
+
6. Send me a pull request!
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "object-send"
|
8
|
+
gem.summary = %Q{Object#send? similar to Object#try?, but works for nil and with arguments.}
|
9
|
+
gem.description = IO.read('./README.markdown')
|
10
|
+
gem.description.force_encoding 'UTF-8' if gem.description.respond_to? :force_encoding
|
11
|
+
gem.email = "kim@burgestrand.se"
|
12
|
+
gem.homepage = "http://github.com/Burgestrand/send?"
|
13
|
+
gem.authors = ["Kim Burgestrand"]
|
14
|
+
gem.rubyforge_project = "object-send"
|
15
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'spec/rake/spectask'
|
23
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
24
|
+
spec.libs << 'lib' << 'spec'
|
25
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
26
|
+
end
|
27
|
+
|
28
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
29
|
+
spec.libs << 'lib' << 'spec'
|
30
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
31
|
+
spec.rcov = true
|
32
|
+
end
|
33
|
+
|
34
|
+
task :spec => :check_dependencies
|
35
|
+
|
36
|
+
task :default => :spec
|
37
|
+
|
38
|
+
require 'rake/rdoctask'
|
39
|
+
Rake::RDocTask.new do |rdoc|
|
40
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
41
|
+
|
42
|
+
rdoc.rdoc_dir = 'rdoc'
|
43
|
+
rdoc.title = "send? #{version}"
|
44
|
+
rdoc.rdoc_files.include('README*')
|
45
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
46
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.1
|
data/lib/object/send.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
class Object
|
2
|
+
# Returns the result of +method+, or +nil+ if +method+ is not a public method.
|
3
|
+
#
|
4
|
+
# @param Symbol method Method name
|
5
|
+
# @param [anyargs, …] *args Any number of arguments
|
6
|
+
# @param &block block Optional block
|
7
|
+
# @return Whatever +method+ returns, or +nil+
|
8
|
+
def send?(method, *args, &block)
|
9
|
+
send(method, *args, &block) if respond_to? method
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class NilClass
|
14
|
+
# Always return +nil+ for +NilClass+
|
15
|
+
#
|
16
|
+
# @see Object#send
|
17
|
+
def send?(*args, &block)
|
18
|
+
nil
|
19
|
+
end
|
20
|
+
end
|
data/object-send.gemspec
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{object-send}
|
8
|
+
s.version = "1.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Kim Burgestrand"]
|
12
|
+
s.date = %q{2010-08-01}
|
13
|
+
s.description = %q{What is send?
|
14
|
+
=============
|
15
|
+
It’s a tiny wee ruby gem that is a fork of [Object#try](http://ozmm.org/posts/try.html)
|
16
|
+
and [Object#try from Rails](http://api.rubyonrails.org/classes/Object.html#M000027). It will *never* throw a NoMethodError (no matter the receiver), and returns nil
|
17
|
+
if called on a nil-class or if the method in the receiver does not exist.
|
18
|
+
|
19
|
+
Note on Patches/Pull Requests
|
20
|
+
-----------------------------
|
21
|
+
|
22
|
+
1. [Fork me!](http://github.com/Burgestrand/send-/fork)
|
23
|
+
2. Write tests for your new feature or bug fix (important, I don’t want
|
24
|
+
to break your stuff in a future update by accident!)
|
25
|
+
3. Hack away on the code; make your tests pass.
|
26
|
+
4. Commit! Don’t touch Rakefile, version or git history in any of the
|
27
|
+
commits you want me to pick.
|
28
|
+
5. ???
|
29
|
+
6. Send me a pull request!
|
30
|
+
}
|
31
|
+
s.email = %q{kim@burgestrand.se}
|
32
|
+
s.extra_rdoc_files = [
|
33
|
+
"LICENSE",
|
34
|
+
"README.markdown"
|
35
|
+
]
|
36
|
+
s.files = [
|
37
|
+
".document",
|
38
|
+
".gitignore",
|
39
|
+
"LICENSE",
|
40
|
+
"README.markdown",
|
41
|
+
"Rakefile",
|
42
|
+
"VERSION",
|
43
|
+
"lib/object/send.rb",
|
44
|
+
"object-send.gemspec",
|
45
|
+
"spec/send_spec.rb",
|
46
|
+
"spec/spec.opts",
|
47
|
+
"spec/spec_helper.rb"
|
48
|
+
]
|
49
|
+
s.homepage = %q{http://github.com/Burgestrand/send?}
|
50
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
51
|
+
s.require_paths = ["lib"]
|
52
|
+
s.rubyforge_project = %q{object-send}
|
53
|
+
s.rubygems_version = %q{1.3.7}
|
54
|
+
s.summary = %q{Object#send? similar to Object#try?, but works for nil and with arguments.}
|
55
|
+
s.test_files = [
|
56
|
+
"spec/send_spec.rb",
|
57
|
+
"spec/spec_helper.rb"
|
58
|
+
]
|
59
|
+
|
60
|
+
if s.respond_to? :specification_version then
|
61
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
62
|
+
s.specification_version = 3
|
63
|
+
|
64
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
65
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
66
|
+
else
|
67
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
68
|
+
end
|
69
|
+
else
|
70
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
data/spec/send_spec.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
class TestObject
|
4
|
+
def i_exist(*args)
|
5
|
+
args
|
6
|
+
end
|
7
|
+
|
8
|
+
def i_want_blocks(first = nil, &block)
|
9
|
+
yield first
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
def i_am_private(*args)
|
14
|
+
args
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "Send?" do
|
19
|
+
it "should allow send? on nil" do
|
20
|
+
nil.send?(:i_do_not_exist).should equal nil
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should not raise errors on non-nil objects" do
|
24
|
+
TestObject.new.send?(:i_do_not_exist_either).should equal nil
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should take arguments and blocks" do
|
28
|
+
args = ['hello', 'world']
|
29
|
+
|
30
|
+
TestObject.new.send?(:i_exist, *args).should == args
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should never ever call private methods" do
|
34
|
+
TestObject.new.send?(:i_am_private, "whatever").should == nil
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should accept blocks" do
|
38
|
+
TestObject.new.send?(:i_want_blocks, "hello") { |arg| arg }.should == "hello"
|
39
|
+
end
|
40
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: object-send
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 1.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Kim Burgestrand
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-08-01 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rspec
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 13
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 2
|
33
|
+
- 9
|
34
|
+
version: 1.2.9
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
description: "What is send?\n\
|
38
|
+
=============\n\
|
39
|
+
It\xE2\x80\x99s a tiny wee ruby gem that is a fork of [Object#try](http://ozmm.org/posts/try.html)\n\
|
40
|
+
and [Object#try from Rails](http://api.rubyonrails.org/classes/Object.html#M000027). It will *never* throw a NoMethodError (no matter the receiver), and returns nil\n\
|
41
|
+
if called on a nil-class or if the method in the receiver does not exist.\n\n\
|
42
|
+
Note on Patches/Pull Requests\n\
|
43
|
+
-----------------------------\n\n\
|
44
|
+
1. [Fork me!](http://github.com/Burgestrand/send-/fork)\n\
|
45
|
+
2. Write tests for your new feature or bug fix (important, I don\xE2\x80\x99t want\n to break your stuff in a future update by accident!)\n\
|
46
|
+
3. Hack away on the code; make your tests pass.\n\
|
47
|
+
4. Commit! Don\xE2\x80\x99t touch Rakefile, version or git history in any of the \n commits you want me to pick.\n\
|
48
|
+
5. ???\n\
|
49
|
+
6. Send me a pull request!\n"
|
50
|
+
email: kim@burgestrand.se
|
51
|
+
executables: []
|
52
|
+
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files:
|
56
|
+
- LICENSE
|
57
|
+
- README.markdown
|
58
|
+
files:
|
59
|
+
- .document
|
60
|
+
- .gitignore
|
61
|
+
- LICENSE
|
62
|
+
- README.markdown
|
63
|
+
- Rakefile
|
64
|
+
- VERSION
|
65
|
+
- lib/object/send.rb
|
66
|
+
- object-send.gemspec
|
67
|
+
- spec/send_spec.rb
|
68
|
+
- spec/spec.opts
|
69
|
+
- spec/spec_helper.rb
|
70
|
+
has_rdoc: true
|
71
|
+
homepage: http://github.com/Burgestrand/send?
|
72
|
+
licenses: []
|
73
|
+
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options:
|
76
|
+
- --charset=UTF-8
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
hash: 3
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
version: "0"
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
hash: 3
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
version: "0"
|
97
|
+
requirements: []
|
98
|
+
|
99
|
+
rubyforge_project: object-send
|
100
|
+
rubygems_version: 1.3.7
|
101
|
+
signing_key:
|
102
|
+
specification_version: 3
|
103
|
+
summary: Object#send? similar to Object#try?, but works for nil and with arguments.
|
104
|
+
test_files:
|
105
|
+
- spec/send_spec.rb
|
106
|
+
- spec/spec_helper.rb
|