Sha256: 0345c5a7d76211d63405ac1678365ea2cfa8ed65cc8d6b11195e5857c2700e17
Contents?: true
Size: 1.19 KB
Versions: 2
Compression:
Stored size: 1.19 KB
Contents
# frozen_string_literal: true module Rcmdr # Subcommands should extend this module once they are instantiated # so that the Subcommand instance has access to all necessary # class methods for this subcommand to work. module Subcommand class << self def extended(mod) mod.singleton_class.delegate :command_namespace, :commands, :command_add, :command_subcommand_add, :command_prompt, :help, to: mod.class end end # Subcommand-specific instance methods. # # Define Subcommand-specific method equivalents of the Command class # methods needed to make this Subcommand instance unique. # def command_namespace(namespace = nil) # return @command_namespace || name if namespace.nil? # @command_namespace = namespace # end # Subcommands can be used by any Command, so the :command_parent needs # to be unique to this Subcommand instance. def command_parent(parent = nil) return @command_prompt if parent.nil? @command_prompt = parent end def command_namespaces(namespaces = []) command_parent&.command_namespaces(namespaces) namespaces << command_namespace namespaces end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rcmdr-0.1.1.pre.alpha | lib/rcmdr/subcommand.rb |
rcmdr-0.1.0.pre.alpha | lib/rcmdr/subcommand.rb |