Skip to content

Commit

Permalink
refine BasicObject instead of Object
Browse files Browse the repository at this point in the history
  • Loading branch information
olegantonyan committed Jun 10, 2021
1 parent f92c360 commit 8bdff56
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@

# rspec failure tracking
.rspec_status

.ruby-version
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.6.1
2.6.6
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
typerb (0.2.1)
typerb (0.3.0)

GEM
remote: https://rubygems.org/
Expand Down
2 changes: 1 addition & 1 deletion lib/typerb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require 'typerb/exceptional'

module Typerb
refine Object do
refine BasicObject do
def type!(*klasses)
raise ArgumentError, 'provide at least one class' if klasses.empty?
return self if klasses.any? { |kls| is_a?(kls) }
Expand Down
2 changes: 1 addition & 1 deletion lib/typerb/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Typerb
VERSION = '0.2.1'
VERSION = '0.3.0'
end
13 changes: 13 additions & 0 deletions spec/typerb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,19 @@ def initialize(arg)
end
expect { kls.new('hello') }.to raise_error(ArgumentError, 'provide at least one class')
end

it 'works with BasicObject' do
require 'tempfile'
kls = Class.new do
using Typerb

def initialize(arg)
arg.type!(Tempfile)
@arg = arg
end
end
expect { kls.new(Tempfile.new) }.not_to raise_error
end
end

context 'not_nil!' do
Expand Down

0 comments on commit 8bdff56

Please sign in to comment.