I am trying to run the code below in ruby. I am getting a nil value for @selectcells. Any suggestions?
class Neighbor_finder
@@path = "/home/xyz"
def initialize(enodebid,earfcn_dl,distance,spread,mcc,mnc)
@site_details=Hash.new
@radius = distance
@earfcn_dl=earfcn_dl
@spread=spread
@sourceenb=enodebid
@plmn=mcc+mnc
@mcc=mcc
@mnc=mnc
puts "here"
end
def enodeb_cell_finder
enodebid=@sourceenb
earfcn_dl=@earfcn_dl
con=Mysql.new 'localhost','root','root','celldb'
puts "here11"
@site_details=con.query "SELECT * FROM enodeb WHERE enodeb_id LIKE '%#{enodebid}%'"
u = @site_details.fetch_hash
ap u
con.close
@con1 = Mysql.new 'localhost','root','root','celldb'
@selectnodes1 = @con1.query "SELECT * FROM cell_db_eutran_cells WHERE sitename LIKE '%#{enodebid}%' AND earfcn_dl LIKE '#{earfcn_dl}'"
@selectcells=@selectnodes1.num_rows
end
end
d=Neighbor_finder.new("936144","2581",20,60,'311','850').enodeb_cell_finder
ap @selectcells
When I add an ap @selectcells as shown below I do got a valid value. It just appears I can't access value of the instance variable @selectcells from outside.
@selectcells=@selectnodes1.num_rows
ap @selectcells
Add a getter to the class to make it accessible. It is an instance variable after all, and you are trying to get it as if it were a global one:
def selectsells
@selectsells
end
# or: attr_reader :selectsells
And access it via:
d = Neighbor_finder.new("936144","2581",20,60,'311','850')
ap d.enodeb_cell_finder
ap d.selectsells