Ruby Highline – Examples
Examples
Basic usage:
ask("Company? ") { |q| q.default = "none" }Validation:
ask("Age? ", Integer) { |q| q.in = 0..105 }
ask("Name? (last, first) ")
{ |q| q.validate = /\A\w+, ?\w+\Z/ }Type conversion for answers:
ask("Birthday? ", Date)
ask("Interests? (comma sep list) ",
lambda { |str| str.split(/,\s*/) })Reading passwords:
ask("Enter your password: ") { |q| q.echo = false }
ask("Enter your password: ") { |q| q.echo = "x" }ERb based output (with HighLine‘s ANSI color tools):
say("This should be <%= color('bold', BOLD) %>!")Menus:
choose do |menu|
menu.prompt = "Please choose your favorite
programming language? "
menu.choice(:ruby) { say("Good choice!") }
menu.choices(:python, :perl)
{ say("Not from around here, are you?") }
end
Reference --> http://highline.rubyforge.org/doc/


Recent comments
1 year 23 weeks ago
1 year 23 weeks ago
1 year 25 weeks ago
1 year 27 weeks ago
1 year 42 weeks ago
1 year 45 weeks ago
1 year 45 weeks ago
1 year 45 weeks ago
1 year 46 weeks ago
1 year 48 weeks ago