# Parameter Type Checking in methods.Q?

**URL:** <https://www.ruby-forum.com/t/parameter-type-checking-in-methods-q/147216>\
**Category:** Ruby\
**Created:** [August 29, 2008, 1:44pm UTC](https://www.ruby-forum.com/t/parameter-type-checking-in-methods-q/147216 "2008-08-29T13:44:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnpetterson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/41988e/32.png) [@johnpetterson](https://www.ruby-forum.com/u/johnpetterson)\
**Post date:** [August 29, 2008, 1:44pm UTC](https://www.ruby-forum.com/t/parameter-type-checking-in-methods-q/147216/1 "2008-08-29T13:44:28Z")

</div>

Again…just wondering…(and you can probably tell I’m comparing Ruby  
with Java/C here again, following on from the “++” discussion…)

def MyObject  
def my\_method(obj)  
if obj.class!=String then raise “Wrong Type!”  
end  
…stuff…  
end  
end

Would it cause problems with the general syntax to include some sugar to  
rewrite this as:

…  
def my\_method(String obj)  
end  
…

Or is there any quick easy meta-programming to label methods as  
expecting certain types?

Or am I being a big-baby wanting this kind of check, and I should get on  
with the Dynamic Vibe of Ruby ? 🙂

(I just noticed that sometimes I get lost in my own programs by not  
checking types thoroughly; yet Java would have forced me to stop and  
think…)

John

---

<div class="post-metadata">

**Author:** ![johnpetterson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/41988e/32.png) [@johnpetterson](https://www.ruby-forum.com/u/johnpetterson)\
**Post date:** [August 29, 2008, 2:12pm UTC](https://www.ruby-forum.com/t/parameter-type-checking-in-methods-q/147216/2 "2008-08-29T14:12:30Z")

</div>

Hi –

On Fri, 29 Aug 2008, John Pritchard-williams wrote:

> Or am I being a big-baby wanting this kind of check, and I should get on  
> with the Dynamic Vibe of Ruby ? 🙂
> 
> (I just noticed that sometimes I get lost in my own programs by not  
> checking types thoroughly; yet Java would have forced me to stop and  
> think…)

I hate to sound curmudgeonly but please check out the probably  
(literally) 2500 posts about this and related questions from the past.  
It’s been discussed and explained mind-numbingly many times.

David

---

<div class="post-metadata">

**Author:** ![johnpetterson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/41988e/32.png) [@johnpetterson](https://www.ruby-forum.com/u/johnpetterson)\
**Post date:** [August 29, 2008, 2:21pm UTC](https://www.ruby-forum.com/t/parameter-type-checking-in-methods-q/147216/3 "2008-08-29T14:21:52Z")

</div>

> I hate to sound curmudgeonly but please check out the probably  
> (literally) 2500 posts about this and related questions from the past.  
> It’s been discussed and explained mind-numbingly many times.
> 
> David

Apologies. I did have a check on the forum beforehand but didn’t find a  
match - perhaps I need to learn how to search properly… 🙂

[http://www.ruby-forum.com/forum/4?filter=parameter+type+method](http://www.ruby-forum.com/forum/4?filter=parameter+type+method)  
[http://www.ruby-forum.com/forum/4?filter=parameter+type+check](http://www.ruby-forum.com/forum/4?filter=parameter+type+check)  
[http://www.ruby-forum.com/forum/4?filter=parameter+type](http://www.ruby-forum.com/forum/4?filter=parameter+type)  
[http://www.ruby-forum.com/forum/4?filter=parameter+type+sugar](http://www.ruby-forum.com/forum/4?filter=parameter+type+sugar)

(or else there is no simple answer I guess…)

Cheers  
John

---

<div class="post-metadata">

**Author:** ![johnpetterson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/41988e/32.png) [@johnpetterson](https://www.ruby-forum.com/u/johnpetterson)\
**Post date:** [August 29, 2008, 3:00pm UTC](https://www.ruby-forum.com/t/parameter-type-checking-in-methods-q/147216/4 "2008-08-29T15:00:05Z")

</div>

2008/8/29 David A. Black [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> On Fri, 29 Aug 2008, John Pritchard-williams wrote:

> > Or am I being a big-baby wanting this kind of check, and I should get on  
> > with the Dynamic Vibe of Ruby ? 🙂

Exactly. 🙂

> > (I just noticed that sometimes I get lost in my own programs by not  
> > checking types thoroughly; yet Java would have forced me to stop and  
> > think…)
> 
> I hate to sound curmudgeonly but please check out the probably

David, thanks for an English word I have never seen before! Now I  
just need to learn how to spell it without breaking my tongue… 🙂

> (literally) 2500 posts about this and related questions from the past.  
> It’s been discussed and explained mind-numbingly many times.

You mean like

> **[Pink Floyd - Comfortably Numb lyrics | LyricsFreak](https://www.lyricsfreak.com/p/pink+floyd/comfortably+numb_20108779.html)**
>
> Read or print original Comfortably Numb lyrics 2023 updated! Hello, / Is there anybody in there? / Just nod if you can hear me / Is there

?

John, suggested search terms to use “static typing”, “dynamic typing”,  
“duck typing”.

Cheers

robert

---

<div class="post-metadata">

**Author:** ![johnpetterson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/41988e/32.png) [@johnpetterson](https://www.ruby-forum.com/u/johnpetterson)\
**Post date:** [August 29, 2008, 3:16pm UTC](https://www.ruby-forum.com/t/parameter-type-checking-in-methods-q/147216/5 "2008-08-29T15:16:40Z")

</div>

> John, suggested search terms to use “static typing”, “dynamic typing”,  
> “duck typing”.

Thanks ! (and I’ll stop spamming this subject now!)

---

<div class="post-metadata">

**Author:** ![johnpetterson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/41988e/32.png) [@johnpetterson](https://www.ruby-forum.com/u/johnpetterson)\
**Post date:** [August 29, 2008, 3:49pm UTC](https://www.ruby-forum.com/t/parameter-type-checking-in-methods-q/147216/6 "2008-08-29T15:49:54Z")

</div>

Hi –

On Fri, 29 Aug 2008, John Pritchard-williams wrote:

> [http://www.ruby-forum.com/forum/4?filter=parameter+type+method](http://www.ruby-forum.com/forum/4?filter=parameter+type+method)  
> [http://www.ruby-forum.com/forum/4?filter=parameter+type+check](http://www.ruby-forum.com/forum/4?filter=parameter+type+check)  
> [http://www.ruby-forum.com/forum/4?filter=parameter+type](http://www.ruby-forum.com/forum/4?filter=parameter+type)  
> [http://www.ruby-forum.com/forum/4?filter=parameter+type+sugar](http://www.ruby-forum.com/forum/4?filter=parameter+type+sugar)
> 
> (or else there is no simple answer I guess…)

Try googling for: “type checking” ruby (even though 99% of the time  
it’s really class/module ancestry checking, it gets raised as type  
checking so that’s a better bet for searching).

David
