https://github.com/sampersand/blankity
Provides a "Blank" and `ToXXX` classes in ruby
https://github.com/sampersand/blankity
blank rbs ruby
Last synced: 3 months ago
JSON representation
Provides a "Blank" and `ToXXX` classes in ruby
- Host: GitHub
- URL: https://github.com/sampersand/blankity
- Owner: sampersand
- License: mit
- Created: 2025-10-20T18:06:54.000Z (8 months ago)
- Default Branch: master
- Last Pushed: 2025-11-11T01:08:27.000Z (7 months ago)
- Last Synced: 2025-11-30T02:17:04.805Z (6 months ago)
- Topics: blank, rbs, ruby
- Language: Ruby
- Homepage:
- Size: 95.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# 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:
```bash
bundle add blankity
```
If bundler is not being used to manage dependencies, install the gem by executing:
```bash
gem install blankity
```
## Usage
The `Blankity::Blank` class `undef`s all methods (other than `__send__` and `__id__`) from `BasicObject`:
```ruby
# 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:
```ruby
# 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:
```ruby
puts 'hello' + Blankity::To.str(' world')
#=> hello world
puts 'hello'.gsub(/[eo]/, Blankity::To.hash('e' => 'E', 'o' => 'O'))
#=> hEllO
```
The `Blankity::To` module is also a mixin!
```ruby
extend Blankity::To
puts 'hello' + str(' world')
exit int(0)
# Let's get crazy!
system(
hash(
str('HELLO', hash: true) => str('WORLD')
),
ary(str('sh'), str('-sh')),
str('-c'),
str('echo $0 $HELLO $PWD'),
chdir: 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](https://opensource.org/licenses/MIT).