From 4c26d99075e527d94c09c500a6c627e78e388eac Mon Sep 17 00:00:00 2001 From: Matti Schneider Date: Sat, 21 Jun 2014 06:46:57 -0700 Subject: [PATCH] Clarify usage of `super` in Block.render --- Liquid-for-Programmers.md | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Liquid-for-Programmers.md b/Liquid-for-Programmers.md index 3bc62bf..1ea4818 100644 --- a/Liquid-for-Programmers.md +++ b/Liquid-for-Programmers.md @@ -101,11 +101,8 @@ class Random < Liquid::Block end def render(context) - if rand(@rand) == 0 - super - else - '' - end + value = rand(@rand) + super.sub('^^^', value.to_s) # calling `super` returns the content of the block end end @@ -113,7 +110,7 @@ Liquid::Template.register_tag('random', Random) ``` ```ruby -text = " {% random 5 %} wanna hear a joke? {% endrandom %} " +text = " {% random 5 %} you have drawn number ^^^, lucky you! {% endrandom %} " @template = Liquid::Template.parse(text) -@template.render # => In 20% of the cases, this will output "wanna hear a joke?" -``` +@template.render # will return "you have drawn number 1, lucky you!" in 20% of cases +``` \ No newline at end of file