summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorAbinoam Praxedes Marques Jr <abinoam@gmail.com>2015-10-08 00:12:49 -0300
committerAbinoam Praxedes Marques Jr <abinoam@gmail.com>2015-10-09 23:33:48 -0300
commitc95224e2d5cb72d8d791967a38e8b3f5898f74f5 (patch)
tree0a1d04613ca79e7634ff9ee1145874373e704786 /README.md
parent8f8eb73bb873e4b91e04fd82d99935884dbb6f8f (diff)
downloadhighline-c95224e2d5cb72d8d791967a38e8b3f5898f74f5.tar.gz
Change the recommended way of using HighLine on README.md
Until now we have recommended require 'highline/import' But this was causing some name collisions as method names like #say and #ask, are common in other libraries. So we should adopt the more verbose and safer way from 2.0.0 on require 'highline' cli = HighLine.new cli.ask "What do you think?"
Diffstat (limited to 'README.md')
-rw-r--r--README.md43
1 files changed, 28 insertions, 15 deletions
diff --git a/README.md b/README.md
index e8c953f..f6071e5 100644
--- a/README.md
+++ b/README.md
@@ -27,52 +27,65 @@ Documentation
See {HighLine} and {HighLine::Question} for documentation.
-Start hacking in your code with HighLine with:
+Usage
+-----
```ruby
-require 'highline/import'
-```
-Examples
---------
+require 'highline'
+
+# Basic usage
-Basic usage:
+cli = HighLine.new
+answer = cli.ask "What do you think?"
+puts "You have answered: #{answer}"
-ask("Company? ") { |q| q.default = "none" }
+
+# Default answer
+
+cli.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/ }
+cli.ask("Age? ", Integer) { |q| q.in = 0..105 }
+cli.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*/) })
+cli.ask("Birthday? ", Date)
+cli.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" }
+cli.ask("Enter your password: ") { |q| q.echo = false }
+cli.ask("Enter your password: ") { |q| q.echo = "x" }
# ERb based output (with HighLine's ANSI color tools):
-say("This should be <%= color('bold', BOLD) %>!")
+cli.say("This should be <%= color('bold', BOLD) %>!")
# Menus:
-choose do |menu|
+cli.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
```
+If you want to save up some characteres, you can inject/import HighLine methods on Kernel by doing the following. Be aware to avoid name collisions at the main namespace.
+
+```ruby
+require 'highline/import'
+
+say "Now you can use #say directly"
+```
+
For more examples see the examples/ directory of this project.
Requirements