https://github.com/danielpclark/mightystring
Making Ruby Strings Powerful
https://github.com/danielpclark/mightystring
ruby string string-manipulation strings
Last synced: 11 months ago
JSON representation
Making Ruby Strings Powerful
- Host: GitHub
- URL: https://github.com/danielpclark/mightystring
- Owner: danielpclark
- License: mit
- Created: 2012-10-08T00:18:58.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2017-03-20T19:31:11.000Z (almost 9 years ago)
- Last Synced: 2025-03-18T03:51:31.368Z (11 months ago)
- Topics: ruby, string, string-manipulation, strings
- Language: Ruby
- Size: 135 KB
- Stars: 27
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
## MightyString
[](http://badge.fury.io/rb/mightystring)
[](https://travis-ci.org/danielpclark/MightyString)
Powerful methods for your strings.
## Install
Add this to your Gemfile and then run `bundle install`.
```ruby
gem 'mightystring', '~> 1.0'
```
Or you can just install and use it manually.
```ruby
gem install mightystring
```
## Usage
```ruby
# String#at
"abc".at(0)
# => "a"
"0123456789".at(-1)
# => "9"
"vwq".at(5)
# => nil
# String#del
"asdfasdf".del(0..2)
# => "fasdf"
"asdfasdf".del(1)
# => "adfasdf"
"asdfasdf".del([1,3])
# => "adasdf"
"asdfasdf".del("a")
# => "sdfsdf"
# String#del!
str = "asdfasdf"
str.del!("sd")
str
# => "afaf"
str.del!(1..2)
str
# => "af"
# String#first
"asdf".first
# => "a"
# String#last
"asdf".last
# => "f"
# String#pop
"asdf".pop
# => "f"
# String#push
"asdf".push("r")
# => "asdfr"
# String#shift
"asdf".shift
# => "a"
# String#sort
str = "asdf"
str.sort
# => "adfs"
str
# => "asdf"
# String#sort!
str = "asdf"
str.sort!
# => "adfs"
str
# => "adfs"
# String#unshift
"asdf".unshift("r")
# => "rasdf"
# String#values_at
"asdfasdfasdf".values_at(0,5,-1)
# => ["a", "s", "f"]
# String#index_all
"012324507654301243".index_all( "0" )
# => [0,7,13]
"the apple is the best fruit in the world".index_all( "the" )
# => [0, 13, 31]
"asdfasdfasdf".index_all( /sd/ )
# => [1,5,9]
# String#sift
"qwertyuiop".sift( "aeiou" )
# => "euio"
"qa2ws3ed4rf5tg6yh7uj8ik9ol".sift( Range.new( "0", "9" ) )
# => "23456789"
# String#head
"asdf".head
# => "a"
"asdf".head(3)
# => "asd"
# String#tail
"asdf".tail
# => "sdf"
"asdf".tail(3)
# => "f"
# String#bhead and String#bisect_head
"asdf".bhead
# => ["a", "sdf"]
"asdf".bhead(3)
# => ["asd", "f"]
# String#btail and String#bisect_tail
"asdf".btail
# => ["sdf", "a"]
"asdf".btail(3)
# => ["f", "asd"]
```
## Extras
* MightyString::HTML.text provides a more ideal HTML to ASCII formatting output. This is an advanced block "filtering" module. It works very well with, currently, extremely rare cases that fall through it's fingers. Regardless it's beautiful, and will strive to be more so.
Look at the test/mightystring_test.rb for case usages of each feature.