Module: Beet::Interaction

Included in:
Executor
Defined in:
lib/beet/interaction.rb

Instance Method Summary collapse

Instance Method Details

#ask(string) ⇒ Object

Get a user’s input

Example

answer = ask("Should I freeze the latest Rails?")
freeze! if ask("Should I freeze the latest Rails?") == "yes"


20
21
22
23
24
# File 'lib/beet/interaction.rb', line 20

def ask(string)
  say(string)
  print '> '
  STDIN.gets.strip
end

#no?(question) ⇒ Boolean

Helper to test if the user does NOT say yes(y)?

Example

capify! if no?("Will you be using vlad to deploy your application?")

Returns:

  • (Boolean)


43
44
45
# File 'lib/beet/interaction.rb', line 43

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

#say(string) ⇒ Object

Print text to the console

Example

say("This is the default. You probably shouldn't change it.")


9
10
11
# File 'lib/beet/interaction.rb', line 9

def say(string)
  puts "#{string}"
end

#yes?(question) ⇒ Boolean

Helper to test if the user says yes(y)?

Example

freeze! if yes?("Should I freeze the latest Rails?")

Returns:

  • (Boolean)


32
33
34
35
# File 'lib/beet/interaction.rb', line 32

def yes?(question)
  answer = ask(question).downcase
  answer == "y" || answer == "yes"
end