# Missing Method Errors

**URL:** <https://www.ruby-forum.com/t/missing-method-errors/92588>\
**Category:** Ruby\
**Created:** [April 21, 2007, 4:00am UTC](https://www.ruby-forum.com/t/missing-method-errors/92588 "2007-04-21T04:00:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ari\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a698b9/32.png) [@Ari\_B](https://www.ruby-forum.com/u/Ari_B)\
**Post date:** [April 21, 2007, 4:00am UTC](https://www.ruby-forum.com/t/missing-method-errors/92588/1 "2007-04-21T04:00:27Z")

</div>

Hi all,  
This is my first post here, so don’t dish out the loser points to me  
so heartily.

I have only recently gotten into Ruby, and I was writing my own  
methods that I might use in a couple future programs (they were YAML  
things, like open and closing a file, and reading a file). I saved it  
as yaml.rb . However, when I require it ( require ‘yaml.rb’) and then  
try to call a method I had defined in yaml.rb, I get an error saying  
that the method had not been defined yet:

test.rb:8: undefined method `yaml\_save’ for main:Object (NoMethodError)

yaml\_save was the method I had tried to use.  
Any thoughts? Suggestions? Flames?

Part II  
The missing command

Today I was in the car and was coding on my dad’s laptop (Windows  
XP), and I was writing a shuffling algorithm. I had used the .pop  
command in it once, and it worked. But then all of a sudden Ruby was  
saying that there was no command ‘pop’. The syntax I had used it in  
was like so:

b = some\_array.pop

Once again, any thoughts? Suggestions? Flames?

--------------------------------------------|  
If you’re not living on the edge,  
then you’re just wasting space.

---

<div class="post-metadata">

**Author:** ![Ari\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a698b9/32.png) [@Ari\_B](https://www.ruby-forum.com/u/Ari_B)\
**Post date:** [April 21, 2007, 4:20am UTC](https://www.ruby-forum.com/t/missing-method-errors/92588/2 "2007-04-21T04:20:27Z")

</div>

> test.rb:8: undefined method `yaml\_save’ for main:Object (NoMethodError)
> 
> yaml\_save was the method I had tried to use.  
> Any thoughts? Suggestions? Flames?

The code that cause this issue would be nice… but it looks like you  
are calling it from an Object something like this:

a = Object.new  
a.yaml\_save

Anyway, this message is saying that the method that you are trying to  
call could not be found (i.e. it’s undefined). Try this:

a = Object.new  
a.asdf

Same error…

---

<div class="post-metadata">

**Author:** ![Ari\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a698b9/32.png) [@Ari\_B](https://www.ruby-forum.com/u/Ari_B)\
**Post date:** [April 21, 2007, 8:54am UTC](https://www.ruby-forum.com/t/missing-method-errors/92588/3 "2007-04-21T08:54:39Z")

</div>

Ari B. wrote:

> Hi all,  
> This is my first post here, so don’t dish out the loser points to me  
> so heartily.
> 
> I have only recently gotten into Ruby, and I was writing my own methods  
> that I might use in a couple future programs (they were YAML things,  
> like open and closing a file, and reading a file). I saved it as yaml.rb  
> .  
> That’s unlucky - there’s a yaml.rb in the standard library which require  
> loads in preference to yours. Try renaming your yaml.rb, or moving it  
> into a folder so that you can call “require ‘ari/yaml’”, or some  
> equivalent. As an aside, it’s usual (and, under some circumstances,  
> required) to leave off the file extension with require.

> Part II  
> The missing command
> 
> Today I was in the car and was coding on my dad’s laptop (Windows XP),  
> and I was writing a shuffling algorithm. I had used the .pop command in  
> it once, and it worked. But then all of a sudden Ruby was saying that  
> there was no command ‘pop’. The syntax I had used it in was like so:
> 
> b = some\_array.pop

Sounds like some\_array isn’t actually an array. Care to post the code  
that’s causing the error?

---

<div class="post-metadata">

**Author:** ![Ari\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a698b9/32.png) [@Ari\_B](https://www.ruby-forum.com/u/Ari_B)\
**Post date:** [April 22, 2007, 12:04pm UTC](https://www.ruby-forum.com/t/missing-method-errors/92588/4 "2007-04-22T12:04:43Z")

</div>

On 4/21/07, Ari B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> require ‘yaml.rb’  
> puts(read\_array == test\_array)
> 
> def yaml\_load filename  
> yaml\_string = File.read filename
> 
> YAML::load yaml\_string  
> end

You should really use, some other name for your library because as  
pointed Alex, its in conflict with ruby standard library.

---

<div class="post-metadata">

**Author:** ![Ari\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a698b9/32.png) [@Ari\_B](https://www.ruby-forum.com/u/Ari_B)\
**Post date:** [April 21, 2007, 4:54pm UTC](https://www.ruby-forum.com/t/missing-method-errors/92588/5 "2007-04-21T16:54:19Z")

</div>

On Apr 20, 2007, at 10:20 PM, removed\_email\_address@domain.invalid wrote:

> The code that cause this issue would be nice… but it looks like you  
> are calling it from an Object something like this:
> 
> a = Object.new  
> a.yaml\_save

The code I’m using is this:

require ‘yaml.rb’

filename = ‘fun.txt’  
test\_array = [‘hey’,  
‘look’,  
‘zoo’]

yaml\_save test\_array, filename

read\_array = yaml\_load filename

puts(read\_array == test\_array)

The yaml.rb code is:

require ‘yaml’

def yaml\_save object, filename  
File.open filename, ‘w’ do |f|  
f.write(object.to\_yaml)  
end  
end

def yaml\_load filename  
yaml\_string = File.read filename

YAML::load yaml\_string  
end

~ Ari  
English is like a pseudo-random number generator - there are a  
bajillion rules to it, but nobody cares.
