I’m in desperate need of help in creating a Letter Histogram in ruby, here is what I need the end product to produce.
irb(main):001:0> load ‘LetterHistogram.rb’
=> true
irb(main):002:0> h = LetterHistogram.new
=> #<LetterHistogram:0x00000000034fb020 @text=“Hello World!”>
irb(main):003:0> h.text => “Hello World!”
irb(main):004:0> h.text = “What’s it going to be then, eh?”
=> “What’s it going to be then, eh?”
irb(main):005:0> h.calculateFrequencies
NoMethodError: private method calculateFrequencies' called for #<LetterHistogram:0x00000000034fb020> from (irb):5 from C:/Program Files/Ruby24-x64/bin/irb.cmd:19:in
’
irb(main):006:0> h.display
A:*
B:*
C:
D:
E:***
F:
G:**
H:***
I:**
J:
K:
L:
M:
N:**
O:**
P:
Q:
R:
S:*
T:****
U:
V:
W:*
X:
Y:
Z:
any help on the matter wil be greatly apreciated
here is the code that i have so far
class LetterHistogram
attr_accessor :text
attr_reader :letters
def initialize(text)
h = LetterHistogram.new
{
if
}
@text = gets
@letters = Hash.new(0)
end
def frequency
@text = text.downcase.chars.each do |c|
next if c =~ /\s/
@letters[c] += 1
end
puts(@letters)
end
def histogram
#@letters.each{|key,value| puts "#{key} + ':' + value.to_s + '*' * #{value}" }
end
runme = LetterHistogram.new("World")
runme.frequency
end