Method: Textbringer::Mode.inherited

Defined in:
lib/textbringer/mode.rb

.inherited(child) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/textbringer/mode.rb', line 51

def self.inherited(child)
  base_name = child.name.slice(/[^:]*\z/)
  child.mode_name = base_name.sub(/Mode\z/, "")
  command_name = base_name.sub(/\A[A-Z]/) { |s| s.downcase }.
    gsub(/(?<=[a-z])([A-Z])/) {
      "_" + $1.downcase
    }
  command = command_name.intern
  hook = (command_name + "_hook").intern
  child.command_name = command
  child.hook_name = hook
  define_command(command) do
    Buffer.current.apply_mode(child)
  end
  @@mode_list.push(child)
  child.instance_variable_set(:@syntax_table, DEFAULT_SYNTAX_TABLE.dup)
end