forked from sponsoredbythewind/extlib
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class TrueClass | ||
def try_dup | ||
self | ||
end | ||
end | ||
|
||
class FalseClass | ||
def try_dup | ||
self | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,10 @@ def find_const(const_name) | |
nested_const_lookup(const_name) | ||
end | ||
end | ||
|
||
def try_dup | ||
self | ||
end | ||
|
||
private | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class NilClass | ||
def try_dup | ||
self | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Numeric | ||
def try_dup | ||
self | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper')) | ||
|
||
describe "try_dup" do | ||
it "returns a duplicate version on regular objects" do | ||
obj = Object.new | ||
oth = obj.try_dup | ||
obj.should_not === oth | ||
end | ||
|
||
it "returns self on Numerics" do | ||
obj = 12 | ||
oth = obj.try_dup | ||
obj.should === oth | ||
end | ||
|
||
it "returns self on true" do | ||
obj = true | ||
oth = obj.try_dup | ||
obj.should === oth | ||
end | ||
|
||
it "returns self on false" do | ||
obj = false | ||
oth = obj.try_dup | ||
obj.should === oth | ||
end | ||
|
||
it "returns self on nil" do | ||
obj = nil | ||
oth = obj.try_dup | ||
obj.should === oth | ||
end | ||
|
||
it "returns self on modules" do | ||
obj = Extlib | ||
oth = obj.try_dup | ||
obj.object_id.should == oth.object_id | ||
end | ||
end |