晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。   林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。   见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝)   既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。   南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。 sh-3ll

HOME


sh-3ll 1.0
DIR:/opt/alt/ruby27/share/ruby/irb/ext/
Upload File :
Current File : //opt/alt/ruby27/share/ruby/irb/ext/history.rb
# frozen_string_literal: false
#
#   history.rb -
#   	$Release Version: 0.9.6$
#   	$Revision$
#   	by Keiju ISHITSUKA(keiju@ruby-lang.org)
#
# --
#
#
#

module IRB # :nodoc:

  class Context

    NOPRINTING_IVARS.push "@eval_history_values"

    # See #set_last_value
    alias _set_last_value set_last_value

    def set_last_value(value)
      _set_last_value(value)

      if defined?(@eval_history) && @eval_history
        @eval_history_values.push @line_no, @last_value
        @workspace.evaluate self, "__ = IRB.CurrentContext.instance_eval{@eval_history_values}"
      end

      @last_value
    end

    remove_method :eval_history= if method_defined?(:eval_history=)
    # The command result history limit. This method is not available until
    # #eval_history= was called with non-nil value (directly or via
    # setting <code>IRB.conf[:EVAL_HISTORY]</code> in <code>.irbrc</code>).
    attr_reader :eval_history
    # Sets command result history limit. Default value is set from
    # <code>IRB.conf[:EVAL_HISTORY]</code>.
    #
    # +no+ is an Integer or +nil+.
    #
    # Returns +no+ of history items if greater than 0.
    #
    # If +no+ is 0, the number of history items is unlimited.
    #
    # If +no+ is +nil+, execution result history isn't used (default).
    #
    # History values are available via <code>__</code> variable, see
    # IRB::History.
    def eval_history=(no)
      if no
        if defined?(@eval_history) && @eval_history
          @eval_history_values.size(no)
        else
          @eval_history_values = History.new(no)
          IRB.conf[:__TMP__EHV__] = @eval_history_values
          @workspace.evaluate(self, "__ = IRB.conf[:__TMP__EHV__]")
          IRB.conf.delete(:__TMP_EHV__)
        end
      else
        @eval_history_values = nil
      end
      @eval_history = no
    end
  end

  # Represents history of results of previously evaluated commands.
  #
  # Available via <code>__</code> variable, only if <code>IRB.conf[:EVAL_HISTORY]</code>
  # or <code>IRB::CurrentContext().eval_history</code> is non-nil integer value
  # (by default it is +nil+).
  #
  # Example (in `irb`):
  #
  #    # Initialize history
  #    IRB::CurrentContext().eval_history = 10
  #    # => 10
  #
  #    # Perform some commands...
  #    1 + 2
  #    # => 3
  #    puts 'x'
  #    # x
  #    # => nil
  #    raise RuntimeError
  #    # ...error raised
  #
  #    # Inspect history (format is "<item number> <evaluated value>":
  #    __
  #    # => 1 10
  #    # 2 3
  #    # 3 nil
  #
  #    __[1]
  #    # => 10
  #
  class History

    def initialize(size = 16)  # :nodoc:
      @size = size
      @contents = []
    end

    def size(size) # :nodoc:
      if size != 0 && size < @size
        @contents = @contents[@size - size .. @size]
      end
      @size = size
    end

    # Get one item of the content (both positive and negative indexes work).
    def [](idx)
      begin
        if idx >= 0
          @contents.find{|no, val| no == idx}[1]
        else
          @contents[idx][1]
        end
      rescue NameError
        nil
      end
    end

    def push(no, val)  # :nodoc:
      @contents.push [no, val]
      @contents.shift if @size != 0 && @contents.size > @size
    end

    alias real_inspect inspect

    def inspect  # :nodoc:
      if @contents.empty?
        return real_inspect
      end

      unless (last = @contents.pop)[1].equal?(self)
        @contents.push last
        last = nil
      end
      str = @contents.collect{|no, val|
        if val.equal?(self)
          "#{no} ...self-history..."
        else
          "#{no} #{val.inspect}"
        end
      }.join("\n")
      if str == ""
        str = "Empty."
      end
      @contents.push last if last
      str
    end
  end
end