Ruby pass like statement

When laying out programs in Python, sometimes during preliminary design,
functions/methods are named but not defined. Instead, ‘pass’ is used to
indicate that it’ll be defined later. It may look like this:

def some_function():

This function will…

pass

Does Ruby have something similar?

Thanks,
Brad

Does pass actually do anything like print to stdout “some_function not
yet defined”?

Farrel L. wrote:

Does pass actually do anything like print to stdout “some_function not
yet defined”?

No, it’s just a place holder.

It would be incorrect (in Python) to not define the function. So, you
place the ‘pass’ statement there to avoid causing errors when testing
your program. Without the pass statement, I believe one would be
required to comment out the undefined function in order to execute the
program. Maybe this is not needed in Ruby???

On Mar 5, 2006, at 6:18 PM, rtilley wrote:

Thanks,
Brad

def some_funtion
end

If the method is not defined the interpreter will throw a
NoMethodError exception.

If you don’t want that you can just define your method with an empty
body

class Test
def foo
end
end

This will return a nil if called.

Farrel

rtilley wrote:

Farrel L. wrote:

Does pass actually do anything like print to stdout “some_function not
yet defined”?

No, it’s just a place holder.

Empty methods are acceptable in Ruby, and they have a return value of
nil.

def some_method
end

This way your code can call this method. It just won’t do anything
useful until you go back and implement the method body later.

Jeff

On 3/5/06, rtilley [email protected] wrote:

When laying out programs in Python, sometimes during preliminary design,
functions/methods are named but not defined. Instead, ‘pass’ is used to
indicate that it’ll be defined later. It may look like this:

def some_function():

This function will…

pass

Does Ruby have something similar?

There’s nothing like this that I know of, but you could always just
pretend:

def some_function
pass
end

#some time later

def some_function
the_real_implementation
end

I think this will earn you a warning about some_function being defined
twice, so it’s slightly ugly. The second def will overwrite the first,
so it should have the semantics you want… provided that second def
really does appear after the first. I don’t know what the semantics of
pass in python are, but in ruby if you actually call (a method that
uses) pass, you’ll get a NoMethodError at runtime. Unless you make a
method called ‘pass’, in which case you’ll be in trouble…

Alternatively, you could just use ‘raise’ or ‘fail’ instead, neither
of which should be defined in well-behaved ruby code.

Hi,

In message “Re: ruby pass like statement”
on Mon, 6 Mar 2006 02:28:39 +0900, rtilley [email protected] writes:

|Maybe this is not needed in Ruby???

No, when you want something empty, you write nothing in there in
Ruby, since it’s empty.

def some_function():
end

No need for any placeholder like “pass” for nothing.

						matz.

p.s.
I know, I know. We have to write “end” everywhere instead.

Yukihiro M. wrote:

def some_function():
end

No need for any placeholder like “pass” for nothing.

Thank you all for the info.

Learning R. has been fun so far. With the Pick Axe book and this
forum, I’ve been able to pick-up a lot in one weekend.

Brad

One thing I saw for perl6 that I liked is the ‘yadda yadda’ operator, 3
periods in a row: …

def some_function()

end

It is sort of like a ‘raise notimplementedexception’. A visual cue to
come back to this method later to implement it.

TODO

Works fine.

Troy

rtilley wrote:

Thanks,
Brad

pass is not needed in Ruby. Indentation forces python to have such a
statement since there would be no way to create empty class/method

empty function:

def fun():
pass

print fun()

will return None just like an empty method in Ruby returns nil.

lopex

On Mar 5, 2006, at 7:54 PM, Troy D. wrote:

TODO

Works fine.

Then make an editor macro that collects them, HTMLifies them, and
allows you to just to any “link” to address the issue. Or by
Textmate which works this way out of the box. :wink:

James Edward G. II