Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add GitHub Flavored Markdown to README

* This makes the example code easier to read,
  especially when perusing the docs on github
  • Loading branch information...
commit e8447eaec40825408f6901193bdfa1e67da8898f 1 parent 1da19d3
@phlipper phlipper authored
Showing with 27 additions and 21 deletions.
  1. +27 −21 README.md
View
48 README.md
@@ -3,32 +3,38 @@ These mostly look like classes created using Struct, but fix two problems with t
Struct constructors can take less than the default number of arguments and set other fields as nil:
- Point = Struct.new(:x,:y)
- Point.new(1)
- => #<struct Point x=1, y=nil>
+```ruby
+Point = Struct.new(:x,:y)
+Point.new(1)
+# => #<struct Point x=1, y=nil>
+```
Structs are also mutable:
- Point = Struct.new(:x,:y)
- p = Point.new(1,2)
- p.x = 2
- p.x
- => 2
+```ruby
+Point = Struct.new(:x,:y)
+p = Point.new(1,2)
+p.x = 2
+p.x
+# => 2
+```
Values fixes both of these:
- Point = Value.new(:x, :y)
- Point.new(1)
- => ArgumentError: wrong number of arguments, 1 for 2
- from /Users/tcrayford/Projects/ruby/values/lib/values.rb:7:in `block (2 levels) in new
- from (irb):5:in new
- from (irb):5
- from /usr/local/bin/irb:12:in `<main>
-
- p = Point.new(1,2)
- p.x = 1
- => NoMethodError: undefined method x= for #<Point:0x00000100943788 @x=0, @y=1>
- from (irb):6
- from /usr/local/bin/irb:12:in <main>
+```ruby
+Point = Value.new(:x, :y)
+Point.new(1)
+# => ArgumentError: wrong number of arguments, 1 for 2
+# from /Users/tcrayford/Projects/ruby/values/lib/values.rb:7:in `block (2 levels) in new
+# from (irb):5:in new
+# from (irb):5
+# from /usr/local/bin/irb:12:in `<main>
+
+p = Point.new(1,2)
+p.x = 1
+# => NoMethodError: undefined method x= for #<Point:0x00000100943788 @x=0, @y=1>
+# from (irb):6
+# from /usr/local/bin/irb:12:in <main>
+```
Value does NOT have all the features of Struct (nor is it meant to).
Please sign in to comment.
Something went wrong with that request. Please try again.