Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nisevi/thanoscase
Randomly removes half the characters of a given string
https://github.com/nisevi/thanoscase
circleci continuous-integration gem monkey-patching rspec rspec-testing ruby ruby-gem ruby-library rubygem rubygems string
Last synced: 2 months ago
JSON representation
Randomly removes half the characters of a given string
- Host: GitHub
- URL: https://github.com/nisevi/thanoscase
- Owner: nisevi
- License: mit
- Created: 2019-04-27T22:11:44.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-08-01T23:47:46.000Z (5 months ago)
- Last Synced: 2024-09-30T11:05:02.946Z (3 months ago)
- Topics: circleci, continuous-integration, gem, monkey-patching, rspec, rspec-testing, ruby, ruby-gem, ruby-library, rubygem, rubygems, string
- Language: Ruby
- Homepage: https://rubygems.org/gems/thanoscase
- Size: 29.3 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[![Maintainability](https://api.codeclimate.com/v1/badges/e44605df0cb27199d63f/maintainability)](https://codeclimate.com/github/nisevi/thanoscase/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/e44605df0cb27199d63f/test_coverage)](https://codeclimate.com/github/nisevi/thanoscase/test_coverage) [![Build Status](https://semaphoreci.com/api/v1/nisevi/thanoscase/branches/master/shields_badge.svg)](https://semaphoreci.com/nisevi/thanoscase) [![Gem Version](https://badge.fury.io/rb/thanoscase.svg)](https://badge.fury.io/rb/thanoscase)
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fnisevi%2Fthanoscase.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fnisevi%2Fthanoscase?ref=badge_shield)# Thanoscase
Wipes out your strings from the universe
# Installation
In your gemfile:
```ruby
gem 'thanoscase'
```or in the console:
```ruby
gem install thanoscase
```# Usage
This gem MonkeyPatches the String class for adding two new methods:
```ruby
class String
def thanoscase!
return self if empty?
half_universe = length/2
half_universe.times { slice!(rand(length)) }
self
enddef thanoscase
dup.thanoscase!
end
end
```It will randomly eliminate half the characters you have in the string:
```ruby
"Marvel Universe".thanoscase # "arel Uve"
"Marvel Universe".thanoscase # "rvlUners"
"Marvel Universe".thanoscase # "Marel ie"
```- If the amount of characters is even you will get half of them as return.
```ruby
"1234".thanoscase # "14"
"1234".thanoscase # "12"
"1234".thanoscase # "34"
```
- If the amount of characters is odd you will get half of them plus one.
```ruby
"123".thanoscase # "23"
"123".thanoscase # "12"
"123".thanoscase # "13"
```
- If you try to apply this method to an empty string, it will return the same empty string.
```ruby
"".thanoscase # ""
```You can also modify the object it`self` like so:
```ruby
str = "Avengers"
# "Avengers"
str.thanoscase
# "Aves"
str
# "Avengers"
str.thanoscase!
# "vegr"
str
# "vegr"
```## License
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fnisevi%2Fthanoscase.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fnisevi%2Fthanoscase?ref=badge_large)