I am trying to create modules and classes based in the Rails lib
directory for my application to call. However, when ever I try and
output the result of a method in the class, all that is returned is a
pound sign. Does anyone have any idea why it is outputting this? I used
the module examples from the Programming Ruby book’s site , and this
code:
class TestModelController < ApplicationController
def index
require ‘ScaleDemo’
validate = ScaleDemo.new
render :text => validate.to_s
Always returns “#”
end
end
lib/ScaleDemo.rb
module MajorScales
def majorNum
@numNotes = 7 if @numNotes.nil?
@numNotes # Return 7
end
end
module PentatonicScales
def pentaNum
@numNotes = 5 if @numNotes.nil?
@numNotes # Return 5?
end
end
class ScaleDemo
include MajorScales
include PentatonicScales
def initialize
puts majorNum # Should be 7
puts pentaNum # Should be 5
end
end
ScaleDemo.new
Thanks for your help and time.