A ruby gem with various helper methods to smooth out your Ruby development.
gem install brightbox-rujitsu --source http://gems.github.com
require "rujitsu" require "rujitsu/grammar"
For using in irb, there's a nice shortcut for you to use:
$ irb -rubygems -rujitsu
(This works because -r is the argument to require a file, and both 'ubygems.rb' and 'ujitsu.rb' exist.)
To require in rails 2.2, add the following to your environment.rb file.
If you use RSpec you might want to add the following to your environments/test.rb:
config.gem "rujitsu", :lib => "rujitsu/grammar"
Run rake docs and open doc/index.html.
The Fixnum class has a couple of extensions allowing you to generate random strings.
5.random_letters 5.random_numbers 5.random_characters
You can also generate a variable length string.
This generates a string of random letters whose length is 3, 4 or 5 characters.
(All the above methods exist in the singular too. eg, 1.random_letter)
The String class has an extension that strips out URL-unfriendly characters.
""$%hello!@ 123 there'".to_url # => "hello-123-there"
The String class has an extension that truncates it to a customisable length with a customisable suffix.
"this is a string".truncate(:length => 15) # => "this is a st..."
As Rubyists we are all familiar with using include? to test if our variable is one of a number of values.
if ['hello', 'world'].include?(@my_value) ...
However, it doesn't read correctly. Rujitsu allows you to write the following as it reads much more like English.
if @my_value.in? ['hello', 'world'] ...
So far the grammar library just adds the method should_recieve for rspec assertions. Use it to find out what it does!
Copyright © 2008 Brightbox Systems Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
See www.brightbox.co.uk/ for contact details.