Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Unix Shell Script Providing Ruby On Rails Enhanced String Methods

DZone's Guide to

Unix Shell Script Providing Ruby On Rails Enhanced String Methods

·
Free Resource
Assuming you have Rails installed as a gem, the following Unix shell script (which I named String, but you can name anything you want when you save the following into a file) allows you to call Ruby String methods (including, importantly, the methods that the Rails ActiveSupport extensions add) on an arbitrary number of arguments, and it will print out the results, e.g.,

$ String camelize snake_case_example another_snake_case_example

The output is:

SnakeCaseExample
AnotherSnakeCaseExample


#!/usr/bin/env ruby

if ARGV.size > 1 then
  gem 'activesupport'
  require 'active_support/core_ext/string/inflections'

  class String
    include ActiveSupport::CoreExtensions::String::Inflections
  end

  command = ARGV.shift
  ARGV.each { |argument|
    puts argument.send( command )
  }
else
  # Print usage information
  puts "Usage: #{File.basename( __FILE__ )}  
  
    [
   
     ...]"
end

   
  
Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}