Class: Space2underscore::Underscore

Inherits:
Object
  • Object
show all
Defined in:
lib/space2underscore/underscore.rb

Instance Method Summary collapse

Constructor Details

#initialize(sentence) ⇒ Underscore

Returns a new instance of Underscore.



5
6
7
# File 'lib/space2underscore/underscore.rb', line 5

def initialize(sentence)
  @sentence = sentence
end

Instance Method Details

#convertObject



9
10
11
12
13
14
15
# File 'lib/space2underscore/underscore.rb', line 9

def convert
  if @sentence.length == 1
    @sentence[0].strip.gsub(/\s/, '_')
  else
    @sentence.join('_')
  end
end