Module: Kernel

Defined in:
lib/core_extensions.rb

Instance Method Summary collapse

Instance Method Details

#literal(object, indent = " ") ⇒ Object


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/core_extensions.rb', line 45

def literal(object, indent = "  ")
  case object
  when Hash
    return "{}" if object.empty?
    literal = "{\n"
    object.each do |k, v|
      literal << "#{indent + "  "}#{literal(k)} => "\
        "#{literal(v, (indent + "  "))},\n"
    end
    literal << "#{indent}}"
    literal
  else
    object.inspect
  end
end

#no?(prompt) ⇒ Boolean

Returns:

  • (Boolean)

66
67
68
# File 'lib/core_extensions.rb', line 66

def no?(prompt)
  !yes?(prompt)
end

#puts(str = "") ⇒ Object


70
71
72
# File 'lib/core_extensions.rb', line 70

def puts(str = "")
  Punch.config.out.puts str
end

#yes?(prompt) ⇒ Boolean

Returns:

  • (Boolean)

61
62
63
64
# File 'lib/core_extensions.rb', line 61

def yes?(prompt)
  puts "#{prompt} (y|n)"
  Punch.config.in.gets.chomp == 'y'
end