Skip to content
Miscellaneous and humble tool-set of useful Ruby.
Ruby
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib
spec
.gitignore
.irbrc
.ruby-version
.travis.yml
Gemfile
LICENSE
README
Rakefile
rubymisc.gemspec

README

1 What is Rubymisc (Ruby miscellaneous | /ˈru:bi ˌmisəˈleiniəs/)
  Miscellaneous tool-set of useful Ruby tricks (RUBY_VERSION >= 1.9.2)

  [https://codeclimate.com/github/ipoval/rubymisc.png]
  [https://secure.travis-ci.org/ipoval/rubymisc.png]

  1.1 Installation
    gem install rubymisc

2 Usage

  2.1 Rbm::Regex

    puts Rbm::Regex.man
    Rbm::Regex.email
    Rbm::Regex.url
    Rbm::Regex.zip
    Rbm::Regex.ipv4 # alternative Resolv::IPv4::Regex
    Rbm::Regex.mac_address
    Rbm::Regex.hexcode
    Rbm::Regex.usd
    Rbm::Regex.date_iso_8601 # yyyy-mm-dd
    Rbm::Regex.strong_password
    Rbm::Regex.negation

  2.2 MultiTierPrice.new(last_usage: 250, tiers: { 0..100 => 0.03, 100..200 => 0.05, 200..300 => 0.07 }).base_charge # => 11.5

  2.3 Object

    #in?
      100.in? [1, 2, 3, 4, 5, 100]  # => true

    #not functor
      100.not.instance_of? Fixnum  # => false

    #and_try functor
      nil.and_try.size             # => nil

    #errors_with_message
      begin
        raise 'Timeout socket'
      rescue errors_with_message /socket/
        p 'socket E'
      end

  2.4 Integer

    #percent_of
      50.percent_of(100)           # => 50.0

  2.5 String

    #^, #xor
      'rubymisc'.xor 'test'        # => "\u0006\u0010\u0011\r\u0019\f\u0000\u0017"

  2.6 ActiveRecord::Base

    .validates_url
    .validates_email
    .validates_image_url

3 Development

  - `gem install bundler`
  - `bundle install`
  - `bundle exec rake spec`
Something went wrong with that request. Please try again.