Skip to content
This repository has been archived by the owner on May 14, 2023. It is now read-only.

Commit

Permalink
Split tutorial files
Browse files Browse the repository at this point in the history
  • Loading branch information
kachick committed May 13, 2013
1 parent c2a57d7 commit d278910
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 52 deletions.
3 changes: 1 addition & 2 deletions README.md
Expand Up @@ -37,8 +37,7 @@ Usage

### Tutorial

Try below senario on the irb/pry.
Or excute "example/tutorial.rb".
Try below senario or excute "example/**_tutorial.rb"

```ruby
require 'io/nosey'
Expand Down
6 changes: 6 additions & 0 deletions example/agree_tutorial.rb
@@ -0,0 +1,6 @@
# coding: us-ascii
require_relative 'helper'

# yes or no
bool = agree? 'Do you like this API?: '
show bool
9 changes: 9 additions & 0 deletions example/choose_tutorial.rb
@@ -0,0 +1,9 @@
# coding: us-ascii
require_relative 'helper'

# choose one
choice = \
choose 'Which Five do you like?: ', 5 => '5 is a Integer',
'five' => '"five" is a String',
:FIVE => ':FIVE is a Symbol'
show choice
6 changes: 6 additions & 0 deletions example/default_tutorial.rb
@@ -0,0 +1,6 @@
# coding: us-ascii
require_relative 'helper'

# with default value
answer = ask "What's your favorite?: ", default: 'ruby'
show answer
8 changes: 8 additions & 0 deletions example/handling_tutorial.rb
@@ -0,0 +1,8 @@
# coding: us-ascii
require_relative 'helper'

# handle return value
age = ask 'How old are you?: ', input: /\A(\d+)\z/,
parse: ->s{Integer s},
return: 10..100
show age
10 changes: 10 additions & 0 deletions example/helper.rb
@@ -0,0 +1,10 @@
# coding: us-ascii
$VERBOSE = true

require_relative '../lib/io/nosey'

include IO::Nosey

def show(obj)
puts "This script understands your input: #{obj.inspect}"
end
11 changes: 1 addition & 10 deletions example/multi_line_tutorial.rb
@@ -1,14 +1,5 @@
# coding: us-ascii
$VERBOSE = true

# setup
require_relative '../lib/io/nosey'

include IO::Nosey

def show(obj)
puts "This script understands your input: #{obj.inspect}"
end
require_relative 'helper'

# multi line mode
name = ask 'Write you poem and exit ctrl+d :) ', multi_line: true
Expand Down
6 changes: 6 additions & 0 deletions example/noecho_tutorial.rb
@@ -0,0 +1,6 @@
# coding: us-ascii
require_relative 'helper'

# get secret word
password = ask "What's your secret word?: ", echo: false
show password
40 changes: 0 additions & 40 deletions example/tutorial.rb

This file was deleted.

6 changes: 6 additions & 0 deletions example/validator_tutorial.rb
@@ -0,0 +1,6 @@
# coding: us-ascii
require_relative 'helper'

# with input validation
name = ask 'What\'s your name?("firstname lastname"): ', input: /\A\w+ \w+\z/
show name

0 comments on commit d278910

Please sign in to comment.