Joel VanderWerf | 1 Jun 2003 01:04
Picon

[RCR] attr_reader :foo?


Would it make sense for attr_reader and friends to associate :foo? with 
the attribute " <at> foo" ?

Consider the following code:

   class C
     attr_accessor :foo?
     def initialize
        <at> foo = true
     end
   end

   c = C.new
   p c.foo?               # ==> false
   c.send("foo?=", true)
   p c.foo?               # ==> true
   p c.instance_variables # [" <at> foo"]

You can call the reader. You have to bend over backwards to call the 
writer. You cannot access the attribute itself from within method 
definitions. You can't even see that it exists using #instance_variables.

Since the use of attr_accessor construct is so pointless in this case, 
why not change the semantics:

   "attr_reader :foo?" defines a method #foo? which gets
   the value of  <at> foo,

   "attr_writer :foo?" defines a method #foo= which sets
(Continue reading)

Lyle Johnson | 1 Jun 2003 01:19
Picon

Re: newbie questions

Steven Ketcham wrote:

> 5/31/2003 2:26:03 PM, Jim Freeze <jim <at> freeze.org> wrote:
> 
>>BTW, after I became rubyized, I found myself not needing 
>>solutions that were based in C/C++, and for this particular
>>case, changed my design to use symbols.
> 
> Could you elaborate on this a little more?

If you're just using an enumerated type to differentiate between 
different mutually exclusive options and don't care what their numeric 
values are -- as appears to be the case in your example -- Ruby symbols 
(a.k.a. "interned" strings or atoms) are a nice alternative:

     class TransferSummary
       def doSummary
         # site list
         doSql (getSiteListSQL(), :SiteList)

         # transfer error count
         doSql (getTransferErrorCountSQL(), :TransferErrorCount)

         # baud rate average
         doSql (getTransferBaudRateAverageSQL(), :BaudRateAverage)

         # transfer count
         doSql (getTransferCountSQL(), :TransferCount)
       end

(Continue reading)

Simon Strandgaard | 1 Jun 2003 01:19
Picon
Favicon

Re: ncurses + redirect output

Thanks Brian. 

I have change from Ncurses.initscr into something like this:

	 <at> term = Ncurses.newterm("xterm-color", $stdout.dup, $stdin)
	Ncurses.set_term( <at> term) 
	fd = File.new("log", "w+")
	$defout.reopen(fd)
	$stdout.reopen(fd)
	$stderr.reopen(fd) 

This seperates Ruby output from Ncurses output.

Unfortunatly this hack makes Ncurses behaving strange, 
suddenly Ncurses output just stops ?  I have to investigate this further.

--
Simon Strandgaard

nobu.nokada | 1 Jun 2003 01:58
Picon

Re: [RCR] attr_reader :foo?

Hi,

At Sun, 1 Jun 2003 08:04:16 +0900,
Joel VanderWerf wrote:
> Since the use of attr_accessor construct is so pointless in this case,
> why not change the semantics:
> 
>    "attr_reader :foo?" defines a method #foo? which gets
>    the value of  <at> foo,
> 
>    "attr_writer :foo?" defines a method #foo= which sets
>    the value of  <at> foo.

Like this?


Index: eval.c
===================================================================
RCS file: /cvs/ruby/src/ruby/eval.c,v
retrieving revision 1.449
diff -u -2 -p -r1.449 eval.c
--- eval.c	30 May 2003 16:07:25 -0000	1.449
+++ eval.c	31 May 2003 23:54:00 -0000
 <at>  <at>  -539,4 +539,5  <at>  <at>  rb_attr(klass, id, read, write, ex)
     ID attriv;
     int noex;
+    int len;

     if (!ex) noex = NOEX_PUBLIC;
 <at>  <at>  -557,9 +558,13  <at>  <at>  rb_attr(klass, id, read, write, ex)
(Continue reading)

Jim Freeze | 1 Jun 2003 02:35
Favicon

Re: newbie questions

On Sunday,  1 June 2003 at  5:12:27 +0900, Steven Ketcham wrote:
> 5/31/2003 2:26:03 PM, Jim Freeze <jim <at> freeze.org> wrote:
> 
> >BTW, after I became rubyized, I found myself not needing 
> >solutions that were based in C/C++, and for this particular
> >case, changed my design to use symbols.
> 
> Could you elaborate on this a little more?
> 

I think Lyle answered this for me.

--

-- 
Jim Freeze
----------
You couldn't even prove the White House staff sane beyond a reasonable
doubt.
		-- Ed Meese, on the Hinckley verdict

John Johnson | 1 Jun 2003 02:50
Picon
Favicon

Re: newbie questions

on 5/31/03 1:00 PM, Steven Ketcham at stedak <at> charter.net wrote:

> 
> Moving from C++
> 

Congratulations!

You're on the path to easier, more expressive, more readable, and more
maintainable code.

I was so used to doing things the hard way in other languages that
Ruby took a little getting used to.

Enjoy!

--

-- 
Regards,
  JJ

Finally using a Mac!

daz | 1 Jun 2003 07:39
Picon

'line' trace event (was Re: IF statement in ruby 1.8.0 ......)


"Yukihiro Matsumoto" <matz <at> ruby-lang.org> wrote:
>
> |> This could be 'bug-lite' in 1.7+ (or i386)?
> |
> |Bug or a feature ? ;-)
>
> A feature.  This is added to accomplish better debugger tracing.
> The call timing may be changed in the future.
>
> matz.
>

< abbreviated ri 1.8 description>
------------------------------------------------- Kernel::set_trace_func
     set_trace_func( aProc ) -> aProc
     set_trace_func( nil ) -> nil
------------------------------------------------------------------------

     Events are: c-call, c-return, call , class, end,
     line (execute code on a new line), raise and return.
</>

puts "ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
set_trace_func proc {| ev, fi, li, oi, bi, cl |
  printf("(%8s)   %s:%-2d (%10s) %s %8s\n",
    ev, fi[-11,11], li, oi.inspect, bi.to_s, cl) if ev == 'line'
}
##- line 7
a =
(Continue reading)

Brian Candler | 1 Jun 2003 08:57
Picon
Favicon

Re: [RCR] attr_reader :foo?

On Sun, Jun 01, 2003 at 08:04:16AM +0900, Joel VanderWerf wrote:
> Consider the following code:
> 
>   class C
>     attr_accessor :foo?
>     def initialize
>        <at> foo = true
>     end
>   end
> 
>   c = C.new
>   p c.foo?               # ==> false
>   c.send("foo?=", true)
>   p c.foo?               # ==> true
>   p c.instance_variables # [" <at> foo"]
> 
> You can call the reader. You have to bend over backwards to call the 
> writer. You cannot access the attribute itself from within method 
> definitions. You can't even see that it exists using #instance_variables.

instance_variables works for me: I get
[" <at> foo?", " <at> foo"]

(version 1.6.8, FreeBSD)

But I agree such an instance variable is not directly accessible (e.g.
 <at> foo?.inspect fails with a parse error)

I guess the ? is being treated as part of the ? : operator rather than the
variable name:
(Continue reading)

nobu.nokada | 1 Jun 2003 09:18
Picon

Re: [RCR] attr_reader :foo?

Hi,

At Sun, 1 Jun 2003 15:57:23 +0900,
Brian Candler wrote:
> instance_variables works for me: I get
> [" <at> foo?", " <at> foo"]

attr_(reader|writer|accessor) don't create instance variable
itself.  When the attribute is assinged, the variable will be
created.

> I guess the ? is being treated as part of the ? : operator rather than the
> variable name:
> 
>       <at> foo?.1:.2   # return .1 if  <at> foo is true or .2 if  <at> foo is false

That's right.  '!' and '?' are allowed at the end of method
names, but not as a part of variable names.

--

-- 
Nobu Nakada

Martin DeMello | 1 Jun 2003 09:19
Picon
Favicon

rdoc: embarrassingly minor complaint

Posted in the hope that someone (i) agrees with me and (ii) has the
design skills to do something about it: rdoc is an excellent tool, but
the font and colour combinations in the default output have always
seemed vaguely clunky to me.  Nothing I can pinpoint, but compare CPAN's
doc generator output
http://search.cpan.org/dist/Algorithm-Permute/Permute.pm with rdoc's
http://jimweirich.umlcoop.net/software/rake/ - the former has a crisper,
cleaner feel to it.

martin


Gmane