# Alias throwing exception: undefined method \`send\_mail' for class \`HeartBeat' (NameError)

**URL:** <https://www.ruby-forum.com/t/alias-throwing-exception-undefined-method-send-mail-for-class-heartbeat-nameerror/140495>\
**Category:** Ruby\
**Created:** [June 15, 2008, 12:05am UTC](https://www.ruby-forum.com/t/alias-throwing-exception-undefined-method-send-mail-for-class-heartbeat-nameerror/140495 "2008-06-15T00:05:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tristincolby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/58f4c7/32.png) [@tristincolby](https://www.ruby-forum.com/u/tristincolby)\
**Post date:** [June 15, 2008, 12:05am UTC](https://www.ruby-forum.com/t/alias-throwing-exception-undefined-method-send-mail-for-class-heartbeat-nameerror/140495/1 "2008-06-15T00:05:35Z")

</div>

I’m having a problem with the code below. when I try and alias the  
send\_mail method, it throws an exception.

undefined method `send_mail' for class`HeartBeat’ (NameError)

Any help would be appreciated. 🙂

class Heartbeat

alias :win\_mail :send\_mail if RUBY\_PLATFORM =~ /mswin32/  
alias :unix\_mail :send\_mail if RUBY\_PLATFORM =~ /linux/

#Abstract method  
def send\_mail  
raise RuntimeError, “Could not detect OS”  
end

```
private

```

# in: hash=\> subject, body, recipients

# out: true if successful

def win\_mail(opts={})  
require ‘win32ole’  
outlook = WIN32OLE.new(‘Outlook.Application’)  
message = outlook.CreateItem(0)  
message.Subject = opts[:subject]  
message.Body = opts[:body]  
message.To = opts[:recipients]  
message.Send  
end

def unix\_mail(opts={})  
end

end

---

<div class="post-metadata">

**Author:** ![tristincolby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/58f4c7/32.png) [@tristincolby](https://www.ruby-forum.com/u/tristincolby)\
**Post date:** [June 15, 2008, 2:38am UTC](https://www.ruby-forum.com/t/alias-throwing-exception-undefined-method-send-mail-for-class-heartbeat-nameerror/140495/2 "2008-06-15T02:38:34Z")

</div>

On Jun 15, 2008, at 0:00, Tristin D. wrote:

> alias :win\_mail :send\_mail if RUBY\_PLATFORM =~ /mswin32/  
> alias :unix\_mail :send\_mail if RUBY\_PLATFORM =~ /linux/
> 
> #Abstract method  
> def send\_mail  
> raise RuntimeError, “Could not detect OS”  
> end

The method isn’t defined in the class until now. Move the alias lines  
to below the def, and it’ll work.

–  
a,b=%Q=Z,O^NPO\r4\_PV\PI\x15^-\x0\v=,email=%%%%c%115%%# Mikael  
Hoilund, CTO  
okay=%#;hmm=(0…a.size).map{|i|((a[i]-email[i]+2)%128).# of [Meta.io](http://Meta.io)  
ApS from  
chr}.join;!email.gsub!‘o’,“%c%c”%[3+?0.\<\<(2),?G.~@];aha=#############  
Denmark  
hmm.scan(/#{‘(.)’\*5}/);!puts(email[1…-12]+aha.shift.zip(\*aha).join)#  
Ruby \<3
