Crayon Meets Ruby
In 1.7.24 I’ve added Ruby and Ruby on Rails as a language on Crayon. Even cooler, I’ve added the
<% ... %>
and similar delimiter tags for eRuby/RHTML. Using Multiple Language Highlighting in Crayon, you can choose HTML as the base language with the lang="html"
attribute or the $[html]...[/html]
Mini Tag and then through in some eRuby syntax. The red bits are Ruby, all else is XHTML. Note you can do the same thing with PHP tags, CSS tags and JavaScript tags.
Here’s the shortcode I used:
$[html] Some HTML first.
-
<% 3.times do %>
- list item <% end %> % $s("ewfwe")
$[rb toolbar="always"] def create_set_and_get(initial_value=0) # Note the default value of 0 closure_value = initial_value return Proc.new {|x| closure_value = x}, Proc.new { closure_value } end setter, getter = create_set_and_get # ie. returns two values setter.call(21) getter.call # => 21 #You can also use a parameter variable as a binding for the closure. #So the above can be rewritten as... def create_set_and_get(closure_value=0) return proc {|x| closure_value = x } , proc { closure_value } end proc {|arg| print arg} Proc.new {|arg| print arg} lambda {|arg| print arg} # introduced in Ruby 1.9 ->(arg) {print arg} # In an object instance variable (denoted with '@'), remember a block. def remember(&a_block) @block = a_block end # Invoke the above method, giving it a block which takes a name. remember {|name| puts "Hello, #{name}!"} # When the time is right (for the object) -- call the closure! @block.call("Jon") # => "Hello, Jon!" [/rb]