# Trivial rails model q

**URL:** <https://www.ruby-forum.com/t/trivial-rails-model-q/162886>\
**Category:** Rails\
**Created:** [March 15, 2009, 4:08am UTC](https://www.ruby-forum.com/t/trivial-rails-model-q/162886 "2009-03-15T04:08:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomjerry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7bcc69/32.png) [@tomjerry](https://www.ruby-forum.com/u/tomjerry)\
**Post date:** [March 15, 2009, 4:08am UTC](https://www.ruby-forum.com/t/trivial-rails-model-q/162886/1 "2009-03-15T04:08:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tomjerry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7bcc69/32.png) [@tomjerry](https://www.ruby-forum.com/u/tomjerry)\
**Post date:** [March 15, 2009, 4:35am UTC](https://www.ruby-forum.com/t/trivial-rails-model-q/162886/2 "2009-03-15T04:35:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tomjerry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7bcc69/32.png) [@tomjerry](https://www.ruby-forum.com/u/tomjerry)\
**Post date:** [March 15, 2009, 4:52am UTC](https://www.ruby-forum.com/t/trivial-rails-model-q/162886/3 "2009-03-15T04:52:17Z")

</div>

Michael G. 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

---

<div class="post-metadata">

**Author:** ![tomjerry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7bcc69/32.png) [@tomjerry](https://www.ruby-forum.com/u/tomjerry)\
**Post date:** [March 16, 2009, 2:32am UTC](https://www.ruby-forum.com/t/trivial-rails-model-q/162886/4 "2009-03-16T02:32:12Z")

</div>

On Mar 15, 3:52 am, Tom J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Michael G. 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
