ruby cast method input variable as string in ruby irb -


how coerce behavior of irb treat variable identifiers strings when used in method signatures?

i trying create irb based calculation tool , want reduce typing of users use tool in irb shell. assume users not ruby programmers or know syntax of ruby. may have facility command line.

i have file

calculator.rb 

inside file is

def calculate(value, units)  ... logic  end 

i instruct user fire irb so

irb -r path/to/calculator.rb 

i instruct user type

calculate(10, inches) 

get return value in irb

how can without requiring user understand have wrap second parameter in quotation marks. in other words don't want user have type

calculate(10, "inches") 

is possible cast user input string instead of variable identifier before passed method inside script? maybe want not possible without fundamentally breaking irb shell?

if non-programmers how using puts , gets?

def calculate   puts "which number convert?"   number = gets.to_i   puts "what want convert to?"   type = gets   # conversion logic   puts result end 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -