Return number of spaces at the beginning of a line

thunk wrote:

Adding a ‘+’ method to Kernel for symbols would reduce code clutter
but still ultimately end up requiring conversion from symbols to
strings to do
the append operation, right?

(ruby 1.9 is allowing me to do more with the ?! chars than I think I
remember 1.8 where I think I remember getting some errors around
this. )

I would not normally care much, or feel a particular need to
understand what is going on under the hood, but I have a performance
issue right here and this happens be one of the things I’m working on.

comments?

then, what would be the best form to add two symbols together (ending
up with a symbol again)

You’re thinking about it the wrong way. A symbol is a pointer to a
specific address in memory, kinda like a variable.
Do you expect this code to work?

a = 5
b = NeuralNetwork.new
puts (a + b).to_s

… You’ll get an error, because a and b are just pointers to the
objects. Symbols are a bit different; while they are “faster” than plain
variables, or than strings, they never get garbage collected (I can not
explain any more than this, but many around here know Ruby’s deep magic
well), and they always refer to the same memory space.

I think you’re using symbols inappropriately. What -are- you doing with
them? If you need to add two names together, then my guess is, just
stick with strings.

On Tue, Mar 30, 2010 at 9:35 AM, Robert K.
[email protected]wrote:

And it has the disadvantage over str[/\A */].length that likely is
slower because of the alternative.

There was a blog by Yehuda K. that implied to me that these globals
weren’t set until you asked for them, but upon re-reading, it isn’t
really
clear to me what actually happens

Josh C. wrote:

On Tue, Mar 30, 2010 at 9:35 AM, Robert K.
[email protected]wrote:

And it has the disadvantage over str[/\A */].length that likely is
slower because of the alternative.

There was a blog by Yehuda K. that implied to me that these globals
weren’t set until you asked for them,

No, they are created as soon as the regular expression is parsed. I
believe Wycats explained that somewhere else, but I can’t find the link
at the moment.

thunk wrote:

On Mar 31, 7:19�am, Aldric G. [email protected] wrote:

I would not normally care much, or feel a particular need to
Do you expect this code to work?

I think you’re using symbols inappropriately. What -are- you doing with
them? If you need to add two names together, then my guess is, just
stick with strings.

Posted viahttp://www.ruby-forum.com/.

just quickly: they start life as a method name so i was hoping they
could stay symbols - but i need a tie breaker for the one level key
that becomes a simpleton method (name) in this “whiteboard” class. i
keep trying to use all symbols. note: ruby is not fighting me with
the /?!/ - so the door seems open to bite the bullet and convert →
append → reconvert but it “hurts” my sense of symmetry - but thanks -
that makes perfect sense (and now that i think about it- it had to be
that way, almost).

thunk

Well, it sounds like you’re using symbols for the wrong purpose, but I
repeat myself.
You may want to take a look at this Rails bit:
http://railsbrain.com/api/rails-2.3.2/doc/index.html?a=C00000033&name=HashWithIndifferentAccess

I’m not saying you should use that, or even think in that direction. It
does however sound similar to what you’re doing.

When designing something, the rule is to ask ‘why’ five times.

You want to use symbols.
Why?
… They start life as a method name.

Okay, well, you can send strings to “call”, not just symbols. So… Why
do you want to use symbols?
If the answer is “Oh, because I want to avoid using strings”, then the
next question is …

Why do you want to avoid using strings? :wink:

It sounds like you’re doing some strangely heavy string manipulation.
Why use symbols at all?

On Fri, Apr 2, 2010 at 8:29 PM, Josh C. [email protected] wrote:

weren’t set until you asked for them,
“When you use =~, there is no actual MatchData object, $1 just behaves like
it was indexing into an implicit MatchData”
Ruby is NOT a Callable Oriented Language (It's Object Oriented)

He doesn’t say anything about $&, but I’d be surprised if it wasn’t the
same.
Though a quick survey of the pickaxe and The Ruby P.ming Language
didn’t imply this implementation detail.

The ‘global’ variables which are set by regular expression matches
aren’t really global, they are ‘frame local’

http://talklikeaduck.denhaven2.com/2008/11/17/in-ruby-globals-arent-always-global


Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Github: rubyredrick (Rick DeNatale) · GitHub
Twitter: @RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale

On Wed, Mar 31, 2010 at 12:11 PM, Aldric G.
[email protected]wrote:

No, they are created as soon as the regular expression is parsed. I
believe Wycats explained that somewhere else, but I can’t find the link
at the moment.

Posted via http://www.ruby-forum.com/.

I was reading Rick DeNatale’s blog Talk Like A Duck which directed me to
a
different post of Yehuda K.'s, where I found a more explicit
explanation:
“When you use =~, there is no actual MatchData object, $1 just behaves
like
it was indexing into an implicit MatchData”

He doesn’t say anything about $&, but I’d be surprised if it wasn’t the
same.
Though a quick survey of the pickaxe and The Ruby P.ming Language
didn’t imply this implementation detail.

On Fri, Apr 2, 2010 at 7:58 PM, Rick DeNatale
[email protected]wrote:

The ‘global’ variables which are set by regular expression matches
aren’t really global, they are ‘frame local’

http://talklikeaduck.denhaven2.com/2008/11/17/in-ruby-globals-arent-always-global

Thanks, Rick, that was actually a reassuring post, I always used to make
sure and use those variables asap in case some other code somewhere else
ended up resetting them. Guess that wasn’t necessary :slight_smile:

Can you confirm Yehuda’s quote that said those variables don’t exist
until
they are called for?

My generalize and filled with Ruby Goodness “WhiteBoard” designed has
dropped performance. Dang! I thought it was all my traces… this
thing has gone from peaking at 2500 (ru’ids) / sec down to 1800 or
so. But it is much more general. I even put in some “channel” logic
to cut down on redundancy. (something like Java “with” statement).
That’s probably not going to make much sense…

My suspicion is that the dynamic code around creating singletons must
be slow compared to just cloning variables (so to say, end result)?

Comments on that?

I probably could have used one of those dynamic structures instead of
a “root” class. Could all the other methods be removed to tweak
things along, would that be the automatic advantage of using
structures in the first place?

…but the singletons and all are just so simple/elegant in this
thing. I have all kinds of methods to dump/trace now. I am not going
to go back! This is a quest now, but I think I will worry about
performance after the thing is fully functional.

(I remember seeing “CleanSlate” in the “Builder” Gem and that gave me
some inspiration on this… did he do that maybe for performance? I
assumed until now it was for avoiding conflicts. Does that make
sense? if so that might be an easy key to getting the lost
performance back.)