Clarify usage of super in Block.render

Matti Schneider
2014-06-21 06:46:57 -07:00
parent 9c57ada1c9
commit 4c26d99075
+4 -7
@@ -101,11 +101,8 @@ class Random < Liquid::Block
end end
def render(context) def render(context)
if rand(@rand) == 0 value = rand(@rand)
super super.sub('^^^', value.to_s) # calling `super` returns the content of the block
else
''
end
end end
end end
@@ -113,7 +110,7 @@ Liquid::Template.register_tag('random', Random)
``` ```
```ruby ```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 = 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
``` ```