diff --git a/lib/rouge/lexers/ruby.rb b/lib/rouge/lexers/ruby.rb index 87b8da2745..7ddc0c3d98 100644 --- a/lib/rouge/lexers/ruby.rb +++ b/lib/rouge/lexers/ruby.rb @@ -309,6 +309,8 @@ def self.detect?(text) state :classname do rule %r/\s+/, Text + rule %r/\w+(::\w+)+/, Name::Class + rule %r/\(/ do token Punctuation push :defexpr diff --git a/spec/visual/samples/ruby b/spec/visual/samples/ruby index 8fc945ef6a..0699b4d129 100644 --- a/spec/visual/samples/ruby +++ b/spec/visual/samples/ruby @@ -78,6 +78,45 @@ class Ipsum < Lorem end end +######## +# Various types of class definitions +######## + +# Singleton class definition +module Table + module Row + DEFAULTS = { cell_width: 80, cell_height: 60 } + + class << self + def styles hsh + hsh.merge DEFAULTS + end + end + end +end + +# Nested class name +module Table + module Row + class Cell < Table::Block + WIDTH = TABLE::ROW::styles[:cell_width] + + def text string, width = WIDTH + string.center width + end + end + end +end + +# Compact class name +class Table::Row::Cell < Table::Block + WIDTH = TABLE::ROW::styles[:cell_width] + + def text string, width = WIDTH + string.center width + end +end + ######## # The popular . :bow: ########