Class: Fatty::Prompt

Inherits:
Object
  • Object
show all
Defined in:
lib/fatty/prompt.rb

Constant Summary collapse

DEFAULT =
"> "

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value = nil, &block) ⇒ Prompt

Returns a new instance of Prompt.



7
8
9
10
11
12
13
14
15
16
# File 'lib/fatty/prompt.rb', line 7

def initialize(value = nil, &block)
  @block =
    if block
      block
    elsif value
      -> { value.to_s }
    else
      -> { DEFAULT }
    end
end

Class Method Details

.ensure(p) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fatty/prompt.rb', line 27

def self.ensure(p)
  case p
  when Prompt
    p
  when Proc
    Prompt.new(&p)
  when String
    Prompt.new(p)
  else
    Prompt.new(DEFAULT)
  end
end

Instance Method Details

#textObject



18
19
20
# File 'lib/fatty/prompt.rb', line 18

def text
  @block.call.to_s
end

#to_sObject Also known as: inspect



22
23
24
# File 'lib/fatty/prompt.rb', line 22

def to_s
  "<Prompt:#{object_id}> `#{text}`"
end