Skip to content

Commit

Permalink
Corrected bug in examples (issue #326); added example headers (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanH committed Jan 26, 2021
1 parent 4b5fae1 commit 7739013
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions README.md
Expand Up @@ -83,6 +83,8 @@ irb> "awesome print".ai

### Examples ###

#### Array

```ruby
$ cat > 1.rb
require "awesome_print"
Expand All @@ -103,7 +105,10 @@ $ ruby 1.rb
:distance => 4.2e+43
}
]
```
#### Hash

```ruby
$ cat > 2.rb
require "awesome_print"
data = { :now => Time.now, :class => Time.now.class, :distance => 42e42 }
Expand All @@ -115,7 +120,11 @@ $ ruby 2.rb
:now => Fri Apr 02 19:55:53 -0700 2010,
:distance => 4.2e+43
}
```

#### Nested array

```ruby
$ cat > 3.rb
require "awesome_print"
data = [ false, 42, %w(forty two) ]
Expand All @@ -125,6 +134,11 @@ ap data, :multiline => false
$ ruby 3.rb
[ false, 42, [ "forty", "two" ], [...] ]

```

#### Class methods

```ruby
$ cat > 4.rb
require "awesome_print"
class Hello
Expand All @@ -138,6 +152,11 @@ $ ruby 4.rb
[0] world(x, y, *z, &blk) Hello
]

```

#### Object methods

```ruby
$ cat > 5.rb
require "awesome_print"
ap (''.methods - Object.methods).grep(/!/)
Expand Down Expand Up @@ -166,14 +185,25 @@ $ ruby 5.rb
[19] upcase!() String
]

```

#### Compare output to value

```ruby
$ cat > 6.rb
require "awesome_print"
ap 42 == ap(42)
^D
$ ruby 6.rb
42
true
$ cat 7.rb

```

#### Array with default output limit

```ruby
$ cat > 7.rb
require "awesome_print"
some_array = (1..1000).to_a
ap some_array, :limit => true
Expand All @@ -188,8 +218,12 @@ $ ruby 7.rb
[998] 999,
[999] 1000
]
```

#### Array with specific output limit

$ cat 8.rb
```ruby
$ cat > 8.rb
require "awesome_print"
some_array = (1..1000).to_a
ap some_array, :limit => 5
Expand All @@ -204,7 +238,7 @@ $ ruby 8.rb
]
```

### Example (Rails console) ###
#### Rails console
```ruby
$ rails console
rails> require "awesome_print"
Expand Down

0 comments on commit 7739013

Please sign in to comment.