Forum: Ruby on Rails trivial rails model q

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
5285b11ee7c127e1fe0158d864919e06?d=identicon&s=25 Tom Jay (tom_j)
on 2009-03-15 04:08
hi, new to ruby/rails (where have i been)

trying to add a basic static method to a model class... anything besides
the normal:

def self.method_name(method_args)
  if method_args == "foo"
    result = true
  else
    result = false
  end
  result
end

which i should know?  do i have to do something to have rails recognise
the addition of a class method like restart the server (which i have
tried to no avail).

sorry for such a basic question.  i am trying to let go of php.

tom.
992f6dd317a9b164e1efc5b674623f38?d=identicon&s=25 Michael Graff (Guest)
on 2009-03-15 04:35
(Received via mailing list)
How are you calling it?  What I see there appears to be correct...

class Foo
  def self.bar(opt)
    if opt == "one"
      return true
    else
      return false
    end
  end
end

puts Foo.bar("one")
puts Foo.bar("two")

$ ruby /tmp/foo.rb
true
false
5285b11ee7c127e1fe0158d864919e06?d=identicon&s=25 Tom Jay (tom_j)
on 2009-03-15 04:52
Michael Graff wrote:


thanks - turns out it was irb not reloading classes.  i just discovered

irb>> load 'measure.rb'

will load any changes you have made to 'measure.rb' if you are using irb
to poke through your rails

thanks again,

tom
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-03-16 02:32
(Received via mailing list)
On Mar 15, 3:52 am, Tom Jay <rails-mailing-l...@andreas-s.net> wrote:
> Michael Graff wrote:
>
> thanks - turns out it was irb not reloading classes.  i just discovered
>
> irb>> load 'measure.rb'
>
> will load any changes you have made to 'measure.rb' if you are using irb
> to poke through your rails
>
There are some subtleties to this. It loads measure.rb again, so if
you have added a method or change a method then those changes will
take effect. It won't however remove a method you deleted. Things like
validations etc will get applied a second time and so on.
If you want to do the same sort of reloading that rails does between
requests then (and this is specific to script/console) you can run
reload!

Fred
This topic is locked and can not be replied to.