Blankity
Blankity is a gem that provides "blank objects," which define minimal methods.
Installation
Install the gem and add to the application's Gemfile by executing:
bundle add blankity
If bundler is not being used to manage dependencies, install the gem by executing:
gem install blankity
Usage
The Blankity::Blank class undefs all methods (other than __send__ and __id__) from BasicObject:
# No methods are defined
blank = Blankity::Blank.new
p defined?(blank.==) #=> nil
p defined?(blank.inspect) #=> nil
# Include specific `Object` methods:
blank = Blankity::Blank.new(with: [:==])
p blank == blank #=> true
# Also supports blocks, which are `instance_exec`ed
p Blankity::Blank.new { def inspect = "hi" } #=> "hi"
Also supplied are Blankity::ToXXX classes, which just define the conversion methods that are used throughout Ruby's stdlib:
# String#* calls `.to_int` on its argument:
p 'a' * Blankity::ToInt.new(3) #=> "aaa"
# File.exist? calls `.to_path` on its argument:
p File.exist? Blankity::ToPath.new('/tmp/foo') #=> false
# Array#[] accepts custom ranges:
p %w[a b c d][Blankity::Range.new(1, 3)] #=> ["b", "c", "d"]
As a convenience, Blankity::To defines these conversion methods:
puts 'hello' + Blankity::To.str(' world')
#=> hello world
puts 'hello'.gsub(/[eo]/, Blankity::To.hash('e' => 'E', 'o' => 'O'))
#=> hEllO
You can include the Blankity::To module to get theeh theo method!
extend Blankity::To
puts 'hello' + to.str(' world')
exit to.int(0)
# Let's get crazy!
system(
to.hash(
to.str('HELLO', hash: true) => to.str('WORLD')
),
to.ary(to.str('sh'), to.str('-sh')),
to.str('-c'),
to.str('echo $0 $HELLO $PWD'),
chdir: to.path('/'),
)
Development
Run tests via rake test and steep check.
Before pushing new versions, make sure to run bundle exec rbs-inline --output lib to generate new rbs signatures, and to update the version.rb file.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/sampersand/blankity.
License
The gem is available as open source under the terms of the MIT License.