Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1afc39a
commit 7db25d4
Showing
6 changed files
with
107 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
begin | ||
$ 5 | ||
rescue SyntaxError | ||
nil | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
The kittens make me happy. They are hidden between the pages of this book, | ||
secretly smiling at you while you read. | ||
|
||
Wasn't that a great story? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
module FattyRBP | ||
class Formatter | ||
|
||
def self.formats | ||
@formats ||= {} | ||
end | ||
|
||
def self.format(name, options={}, &block) | ||
formats[name] = Class.new(FattyRBP::Format, &block) | ||
end | ||
|
||
def self.render(format, options={}) | ||
formats[format].new(options).render | ||
end | ||
end | ||
|
||
class Format | ||
def initialize(options) | ||
# not important | ||
end | ||
end | ||
end | ||
|
||
|
||
class Hello < FattyRBP::Formatter | ||
format :text do | ||
def render | ||
"Hello World" | ||
end | ||
end | ||
|
||
format :html do | ||
def render | ||
"<b>Hello World</b>" | ||
end | ||
end | ||
end | ||
|
||
puts Hello.render(:text) | ||
puts Hello.render(:html) | ||
|
||
|
||
class Goodbye < FattyRBP::Formatter | ||
format :text do | ||
def render | ||
"Goodbye Cruel World!" | ||
end | ||
end | ||
end | ||
|
||
puts Goodbye.render(:text) | ||
|
||
|
||
# Should not have changed | ||
puts Hello.render(:text) | ||
|
||
# Shouldn't exist | ||
puts Goodbye.render(:html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require "pstore" | ||
|
||
class User | ||
|
||
def self.data | ||
@data ||= PStore.new("users.store") | ||
end | ||
|
||
def self.add(id, user_data) | ||
data.transaction do | ||
data[id] = user_data | ||
end | ||
end | ||
|
||
def self.find(id) | ||
data.transaction do | ||
data[id] or raise "User not found" | ||
end | ||
end | ||
|
||
def initialize(id) | ||
@user_id = id | ||
end | ||
|
||
def attributes | ||
self.class.find(@user_id) | ||
end | ||
|
||
def first_name | ||
attributes[:first_name] | ||
end | ||
|
||
end |