# Adding methods, accessing from console and rake tasks

**URL:** <https://www.ruby-forum.com/t/adding-methods-accessing-from-console-and-rake-tasks/165205>\
**Category:** Rails\
**Created:** [April 10, 2009, 5:36am UTC](https://www.ruby-forum.com/t/adding-methods-accessing-from-console-and-rake-tasks/165205 "2009-04-10T05:36:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![LukeG](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f19dbf/32.png) [@LukeG](https://www.ruby-forum.com/u/LukeG)\
**Post date:** [April 10, 2009, 5:36am UTC](https://www.ruby-forum.com/t/adding-methods-accessing-from-console-and-rake-tasks/165205/1 "2009-04-10T05:36:54Z")

</div>

another noob question… how do I add methods to a class such that  
they can be access from the console and from rake?

Details:

I have a ruby script to fetch tweets from the search api. That works  
fine, saves my tweets to the db. I have a separate, basic rails app to  
view and manage the tweets and search queries. All of that works fine,  
too.

Now I want to integrate the script into the rails app so it:  
-runs as a rake task  
-runs from cron  
-runs from a refresh button on the tweets page

The original ruby script has two methods: search\_twitter and  
get\_tweets. I copied those into the Tweet controller, but I cannot  
access them from the rake file or from the console. If I do  
Tweet.methods from the console, neither method shows up.

So - where is the correct place for these methods, and how do I access  
them from rake and the console?

Thanks!

-Luke

---

<div class="post-metadata">

**Author:** ![LukeG](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f19dbf/32.png) [@LukeG](https://www.ruby-forum.com/u/LukeG)\
**Post date:** [April 10, 2009, 9:56am UTC](https://www.ruby-forum.com/t/adding-methods-accessing-from-console-and-rake-tasks/165205/2 "2009-04-10T09:56:28Z")

</div>

On Apr 10, 4:35 am, LukeG [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The original ruby script has two methods: search\_twitter and  
> get\_tweets. I copied those into the Tweet controller, but I cannot  
> access them from the rake file or from the console. If I do  
> Tweet.methods from the console, neither method shows up.
> 
> So - where is the correct place for these methods, and how do I access  
> them from rake and the console?

I’d create a model that did these tweet related tasks (or add them to  
an existing one if appropriate)

Fred

---

<div class="post-metadata">

**Author:** ![LukeG](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f19dbf/32.png) [@LukeG](https://www.ruby-forum.com/u/LukeG)\
**Post date:** [April 10, 2009, 11:53pm UTC](https://www.ruby-forum.com/t/adding-methods-accessing-from-console-and-rake-tasks/165205/3 "2009-04-10T23:53:44Z")

</div>

Putting them in the model helped, getting a quick schooling in OOP  
from someone else helped, too 🙂

I changed the methods to class methods, and now it behaves as  
expected.

Thanks!

On Apr 10, 2:55 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
