Forum: Ruby ruby pass like statement

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
02bd6b98b7c04f9ae5868eda3d01fb73?d=identicon&s=25 rtilley (Guest)
on 2006-03-05 18:21
(Received via mailing list)
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
05be5d6610e2c3f1780aa0e39e902e93?d=identicon&s=25 Farrel Lifson (Guest)
on 2006-03-05 18:24
(Received via mailing list)
Does pass actually do anything like print to stdout "some_function not
yet defined"?
02bd6b98b7c04f9ae5868eda3d01fb73?d=identicon&s=25 rtilley (Guest)
on 2006-03-05 18:30
(Received via mailing list)
Farrel Lifson 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???
9358cc96c46055cd68d4a76a9aefe026?d=identicon&s=25 Daniel Harple (Guest)
on 2006-03-05 18:33
(Received via mailing list)
On Mar 5, 2006, at 6:18 PM, rtilley wrote:

>
> Thanks,
> Brad
>

def some_funtion
end
05be5d6610e2c3f1780aa0e39e902e93?d=identicon&s=25 Farrel Lifson (Guest)
on 2006-03-05 18:34
(Received via mailing list)
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
8217faf2bfdfa7daf10135d41ddd421e?d=identicon&s=25 Jeff Cohen (jeff)
on 2006-03-05 18:34
rtilley wrote:
> Farrel Lifson 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
www.softiesonrails.com
Ab870531383eea6e4d9110317f5401e7?d=identicon&s=25 Caleb Clausen (Guest)
on 2006-03-05 18:37
(Received via mailing list)
On 3/5/06, rtilley <rtilley@vt.edu> 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.
0ec4920185b657a03edf01fff96b4e9b?d=identicon&s=25 Yukihiro Matsumoto (Guest)
on 2006-03-05 18:40
(Received via mailing list)
Hi,

In message "Re: ruby pass like statement"
    on Mon, 6 Mar 2006 02:28:39 +0900, rtilley <rtilley@vt.edu> 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.
02bd6b98b7c04f9ae5868eda3d01fb73?d=identicon&s=25 rtilley (Guest)
on 2006-03-05 20:09
(Received via mailing list)
Yukihiro Matsumoto wrote:
>   def some_function():
>   end
>
> No need for any placeholder like "pass" for nothing.

Thank you all for the info.

Learning Ruby 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
B97225f66bb5caac601b12735d430a0d?d=identicon&s=25 Marcin MielżyÅ?ski (Guest)
on 2006-03-05 22:44
(Received via mailing list)
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
682fff6db11e1a150d6ce17f3b862448?d=identicon&s=25 Doug H (Guest)
on 2006-03-06 02:45
(Received via mailing list)
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.
Fb899458ee6c4ae4884bc3b88da57a1b?d=identicon&s=25 Troy Denkinger (Guest)
on 2006-03-06 02:54
(Received via mailing list)
# TODO

Works fine.

Troy
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2006-03-06 03:34
(Received via mailing list)
On Mar 5, 2006, at 7:54 PM, Troy Denkinger 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.  ;)

James Edward Gray II
This topic is locked and can not be replied to.