Skip to content

Commit 82818c4

Browse files
authored
Merge pull request #61 from ruby/docs-readme-example
README.md: Document "Get form values"
2 parents ab84b7f + f2822f8 commit 82818c4

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

README.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,19 @@ Or install it yourself as:
3232

3333
### Get form values
3434

35+
Given a form with the content `field_name=123`:
36+
3537
```ruby
3638
require "cgi"
3739
cgi = CGI.new
38-
value = cgi['field_name'] # <== value string for 'field_name'
39-
# if not 'field_name' included, then return "".
40-
fields = cgi.keys # <== array of field names
41-
42-
# returns true if form has 'field_name'
43-
cgi.has_key?('field_name')
44-
cgi.has_key?('field_name')
45-
cgi.include?('field_name')
46-
```
40+
value = cgi['field_name'] # => "123"
41+
cgi['flowerpot'] # => ""
42+
fields = cgi.keys # => [ "field_name" ]
4743

48-
CAUTION! cgi['field_name'] returned an Array with the old
49-
cgi.rb(included in Ruby 1.6)
44+
cgi.has_key?('field_name') # => true
45+
cgi.include?('field_name') # => true
46+
cgi.include?('flowerpot') # => false
47+
```
5048

5149
### Get form values as hash
5250

0 commit comments

Comments
 (0)