Last active
December 28, 2015 17:28
-
-
Save alloy-d/7535743 to your computer and use it in GitHub Desktop.
Record (basic) field accesses. Intended for use in Mustache templates.
This file contains hidden or 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
require 'set' | |
class AccessRecorder | |
attr_reader :accessed | |
def initialize | |
@accessed = Set.new | |
end | |
def has_key?(*args) true end | |
def [](key) | |
@accessed << key | |
"{{#{key}}}" | |
end | |
end |
This file contains hidden or 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
recorder = AccessRecorder.new | |
Mustache.render("Hello, {{name}}. Welcome to {{planet}}!", recorder) | |
recorder.accessed.to_a # => [:name, :planet] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment