[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Casting string to IO?

(Adam Block)

8/27/2006 3:36:00 AM

I'm reading log file settings from a YAML file. Since Logger.new can
take either an IO object or string, the YAML could look like:

logger:
output: STDOUT

or

logger:
output: /foo/bar

The problem is that the YAML structure is loaded as strings, so if I
specify STDOUT I get a log file named "STDOUT". Is there an elegant way
around this problem? I see two less-elegant ways:

if yaml["logger"]["output"] == "STDOUT" then
log = Logger.new(STDOUT)
else
...
end

or

log = eval('Logger.new(' + yaml["logger"]["output"] + ')')

etc.

I know casting is bad. Any suggestions appreciated. Thanks!

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

22 Answers

e

8/27/2006 3:49:00 AM

0

Adam Block wrote:
> I'm reading log file settings from a YAML file. Since Logger.new can
> take either an IO object or string, the YAML could look like:
>
> logger:
> output: STDOUT
>
> or
>
> logger:
> output: /foo/bar
>
> The problem is that the YAML structure is loaded as strings, so if I
> specify STDOUT I get a log file named "STDOUT". Is there an elegant way
> around this problem? I see two less-elegant ways:
>
> if yaml["logger"]["output"] == "STDOUT" then
> log = Logger.new(STDOUT)
> else
> ...
> end
>
> or
>
> log = eval('Logger.new(' + yaml["logger"]["output"] + ')')
>
> etc.
>
> I know casting is bad. Any suggestions appreciated. Thanks!

The problem is that you are not casting, you are dealing with
variable names (symbolic names) versus variable contents. In
that light, your solutions are fine unless you have/make a
filesystem file corresponding to STDOUT :)

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

(Adam Block)

8/27/2006 6:08:00 AM

0

Very nice! Thanks!

> output = Kernel.const_get(output) rescue output

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

David Vallner

8/27/2006 10:59:00 AM

0

Adam Block wrote:
> I know casting is bad.

<pedant>
This is probably coercion, not casting. The latter I tend to associate
with conversion between almost-but-not-quite-compatible and
maybe-but-we-can't-tell-until-we-try-compatible types.
</pedant>

David Vallner

TD

6/18/2012 6:03:00 PM

0

On Jun 18, 1:50 pm, charlieguitar <robinsonch...@comcast.net> wrote:
> On Thursday, June 7, 2012 10:00:09 PM UTC-4, Gerry wrote:
> > On 2012-06-08 01:01:41 +0000, Pa                                                                         Everyone has given you an abundance of ideas drawn from music theory so there is no need for more of that type of information.What hasn't been mentioned is simple vizualization.Play a diminished chord at a low point on the neck then play it's corresponding scale and arpeggio.Then move the chord up the neck a minor third and do the same thing again.Continue doing this until you have gone as high as you can go.Since the fingerings for the scales and arpeggios will be the same all of the way up you can achieve this goal rapidly.All that remains is to start trying to connect the various scale and arpeggio patterns up and down the neck.Once that is accomplished you should be able to find three tons of things to play off the chord being discussed. Later,
>
> Charlie
>
>
>
> > I'll be glad to give the first of many bad and wrong ideas likely to
> > cripple any future growth.
>
> > > As far as diminished stuff goes,
>
> > What is "diminished stuff" to you.
>
> > > I understand all the theory and applications, I can play the fingerings
> > > and arpeggios, but when it comes to applying them in a solo I have some
> > > trouble. For some reason the notes are just hard to find, with the
> > > scales looking so similar and you could think of them as whole half of
> > > half whole (dominant)...
>
> > I assume that should read "whole half" OR "half whole", correct?
>
> > > When a diminished chord comes around I cant do much, save for playing
> > > the arpeggio starting on the root, or playing a portion of the scale
> > > also starting on the root.
>
> > If you don't like it when you do that--stop doing that.  Begin with the
> > b5 for a while.  Sure you'll have hesitations at first, then the
> > hesitations will go away as it becomes reflexive.
>
> > But "doing diminished stuff" seems here to be relating to the
> > difficulty of finding and playing diminished scales and diminished arps
> > over a diminished chord. Is that your difficulty? Are you trying to use
> > these in relationship to dominant chords, or only in relationship to
> > diminished chords?
>
> > Can you give examples of a couple of tunes, or locations within a tune,
> > that might be an example of where you're encountering difficulties?
>
> > > Id like to get to the point where I can be able to visualize and play
> > > all the notes, wherever I am on the neck over any diminished or
> > > dominant chord, an be able to play any way starting on any note, etc....
> > > Any pointers here?
>
> > You might guess what my assertion would be: play them all over the neck
> > via a disciplined and methodic regimen, after which you'll have a
> > previous backlog of actual experience whenever you encounter a
> > performance circumstance.
>
> > If your intent is to glue togther the material between a
> > I-b2dim-II-b3dim-II kind of situation, then practice it (methodically)
> > all over the neck and in many positions doing that kind of movement.
> > Doing it in cycles ensure that you're doing it everywhere instead of
> > where it's easiest. If it's relating more to playing diminished
> > materials on secondary dominants like VI7 or II7, then practice it
> > there.
>
> > > I also can't decide on how to practice and think about it, whether I
> > > think only in terms of half whole, or both half and whole ...
>
> > It's the same thing as practicing by *always* starting on the b5th.
> > After awhile that will seem to be predictable and you can move to the
> > b3rd instead.  The same is true of the diminished scale. Find a
> > suitable "reflexive" place to put it, get comfortable with it there,
> > then move to the next difficult location until it loses its difficulty.
>
> > One more thing: Don't concentrate on this to the exclusion of all other
> > aspects of music, to show off, or as the only material in your solos.
> > --
> > If one plays good music, people don't listen and if one plays bad music
> > people don't talk.  -- Oscar Wilde

"What hasn't been mentioned is simple vizualization."

Seeing is believing, as it is said. Therefore, believing will only
enkindle a trusting ear.

Gerry

6/18/2012 6:53:00 PM

0

On 2012-06-18 18:03:22 +0000, TD said:

> "What hasn't been mentioned is simple vizualization."
>
> Seeing is believing, as it is said. Therefore, believing will only
> enkindle a trusting ear.

You are a poet!

Isn't "visualization" the same as the dreaded "geometry" of the guitar?
--
If one plays good music, people don't listen and if one plays bad music
people don't talk. -- Oscar Wilde

TD

6/18/2012 8:24:00 PM

0

On Jun 18, 2:53 pm, Gerry <addr...@domain.com> wrote:
> On 2012-06-18 18:03:22 +0000, TD said:
>
> > "What hasn't been mentioned is simple vizualization."
>
> > Seeing is believing, as it is said. Therefore, believing will only
> > enkindle a trusting ear.
>
> You are a poet!
>
> Isn't "visualization" the same as the dreaded "geometry" of the guitar?
> --
> If one plays good music, people don't listen and if one plays bad music
> people don't talk.  -- Oscar Wilde

Only if you speak of the blind cleaning the blinds.

Mark Cleary

6/18/2012 9:22:00 PM

0

"TD" wrote in message
news:9d4ced2f-cf15-4658-ba0c-bb9b01211a58@m10g2000vbn.googlegroups.com...

On Jun 18, 1:50 pm, charlieguitar <robinsonch...@comcast.net> wrote:
> On Thursday, June 7, 2012 10:00:09 PM UTC-4, Gerry wrote:
> > On 2012-06-08 01:01:41 +0000, Pa
> > Everyone has given you an abundance of ideas drawn from music theory so
> > there is no need for more of that type of information.What hasn't been
> > mentioned is simple vizualization.Play a diminished chord at a low point
> > on the neck then play it's corresponding scale and arpeggio.Then move
> > the chord up the neck a minor third and do the same thing again.Continue
> > doing this until you have gone as high as you can go.Since the
> > fingerings for the scales and arpeggios will be the same all of the way
> > up you can achieve this goal rapidly.All that remains is to start trying
> > to connect the various scale and arpeggio patterns up and down the
> > neck.Once that is accomplished you should be able to find three tons of
> > things to play off the chord being discussed. Later,
>
> Charlie
>
>
>
> > I'll be glad to give the first of many bad and wrong ideas likely to
> > cripple any future growth.
>
> > > As far as diminished stuff goes,
>
> > What is "diminished stuff" to you.
>
> > > I understand all the theory and applications, I can play the
> > > fingerings
> > > and arpeggios, but when it comes to applying them in a solo I have
> > > some
> > > trouble. For some reason the notes are just hard to find, with the
> > > scales looking so similar and you could think of them as whole half of
> > > half whole (dominant)...
>
> > I assume that should read "whole half" OR "half whole", correct?
>
> > > When a diminished chord comes around I cant do much, save for playing
> > > the arpeggio starting on the root, or playing a portion of the scale
> > > also starting on the root.
>
> > If you don't like it when you do that--stop doing that. Begin with the
> > b5 for a while. Sure you'll have hesitations at first, then the
> > hesitations will go away as it becomes reflexive.
>
> > But "doing diminished stuff" seems here to be relating to the
> > difficulty of finding and playing diminished scales and diminished arps
> > over a diminished chord. Is that your difficulty? Are you trying to use
> > these in relationship to dominant chords, or only in relationship to
> > diminished chords?
>
> > Can you give examples of a couple of tunes, or locations within a tune,
> > that might be an example of where you're encountering difficulties?
>
> > > Id like to get to the point where I can be able to visualize and play
> > > all the notes, wherever I am on the neck over any diminished or
> > > dominant chord, an be able to play any way starting on any note,
> > > etc...
> > > Any pointers here?
>
> > You might guess what my assertion would be: play them all over the neck
> > via a disciplined and methodic regimen, after which you'll have a
> > previous backlog of actual experience whenever you encounter a
> > performance circumstance.
>
> > If your intent is to glue togther the material between a
> > I-b2dim-II-b3dim-II kind of situation, then practice it (methodically)
> > all over the neck and in many positions doing that kind of movement.
> > Doing it in cycles ensure that you're doing it everywhere instead of
> > where it's easiest. If it's relating more to playing diminished
> > materials on secondary dominants like VI7 or II7, then practice it
> > there.
>
> > > I also can't decide on how to practice and think about it, whether I
> > > think only in terms of half whole, or both half and whole ...
>
> > It's the same thing as practicing by *always* starting on the b5th.
> > After awhile that will seem to be predictable and you can move to the
> > b3rd instead. The same is true of the diminished scale. Find a
> > suitable "reflexive" place to put it, get comfortable with it there,
> > then move to the next difficult location until it loses its difficulty.
>
> > One more thing: Don't concentrate on this to the exclusion of all other
> > aspects of music, to show off, or as the only material in your solos.
> > --
> > If one plays good music, people don't listen and if one plays bad music
> > people don't talk. -- Oscar Wilde

"What hasn't been mentioned is simple vizualization."

Seeing is believing, as it is said. Therefore, believing will only
enkindle a trusting ear.


Tony,

Your really a theologian "I believe to understand, and understanding
increases my belief".

I have two ears, ( Old Test. and the New Testament), one mind (
monotheistic), 3 ways to play the fingerboard, vertical, horizontal, and
diagonally, ( the Trinity), but when I play I have to have faith in what I
doing is making music.

Does that work?


Deacon Mark Cleary
Epiphany Catholic Church

TD

6/18/2012 9:44:00 PM

0

On Jun 18, 5:21 pm, "mark cleary" <mclear...@comcast.net> wrote:
> "TD"  wrote in message
>
> news:9d4ced2f-cf15-4658-ba0c-bb9b01211a58@m10g2000vbn.googlegroups.com...
>
> On Jun 18, 1:50 pm, charlieguitar <robinsonch...@comcast.net> wrote:
>
>
>
>
>
> > On Thursday, June 7, 2012 10:00:09 PM UTC-4, Gerry wrote:
> > > On 2012-06-08 01:01:41 +0000, Pa
> > > Everyone has given you an abundance of ideas drawn from music theory so
> > > there is no need for more of that type of information.What hasn't been
> > > mentioned is simple vizualization.Play a diminished chord at a low point
> > > on the neck then play it's corresponding scale and arpeggio.Then move
> > > the chord up the neck a minor third and do the same thing again.Continue
> > > doing this until you have gone as high as you can go.Since the
> > > fingerings for the scales and arpeggios will be the same all of the way
> > > up you can achieve this goal rapidly.All that remains is to start trying
> > > to connect the various scale and arpeggio patterns up and down the
> > > neck.Once that is accomplished you should be able to find three tons of
> > > things to play off the chord being discussed. Later,
>
> > Charlie
>
> > > I'll be glad to give the first of many bad and wrong ideas likely to
> > > cripple any future growth.
>
> > > > As far as diminished stuff goes,
>
> > > What is "diminished stuff" to you.
>
> > > > I understand all the theory and applications, I can play the
> > > > fingerings
> > > > and arpeggios, but when it comes to applying them in a solo I have
> > > > some
> > > > trouble. For some reason the notes are just hard to find, with the
> > > > scales looking so similar and you could think of them as whole half of
> > > > half whole (dominant)...
>
> > > I assume that should read "whole half" OR "half whole", correct?
>
> > > > When a diminished chord comes around I cant do much, save for playing
> > > > the arpeggio starting on the root, or playing a portion of the scale
> > > > also starting on the root.
>
> > > If you don't like it when you do that--stop doing that.  Begin with the
> > > b5 for a while.  Sure you'll have hesitations at first, then the
> > > hesitations will go away as it becomes reflexive.
>
> > > But "doing diminished stuff" seems here to be relating to the
> > > difficulty of finding and playing diminished scales and diminished arps
> > > over a diminished chord. Is that your difficulty? Are you trying to use
> > > these in relationship to dominant chords, or only in relationship to
> > > diminished chords?
>
> > > Can you give examples of a couple of tunes, or locations within a tune,
> > > that might be an example of where you're encountering difficulties?
>
> > > > Id like to get to the point where I can be able to visualize and play
> > > > all the notes, wherever I am on the neck over any diminished or
> > > > dominant chord, an be able to play any way starting on any note,
> > > > etc...
> > > > Any pointers here?
>
> > > You might guess what my assertion would be: play them all over the neck
> > > via a disciplined and methodic regimen, after which you'll have a
> > > previous backlog of actual experience whenever you encounter a
> > > performance circumstance.
>
> > > If your intent is to glue togther the material between a
> > > I-b2dim-II-b3dim-II kind of situation, then practice it (methodically)
> > > all over the neck and in many positions doing that kind of movement.
> > > Doing it in cycles ensure that you're doing it everywhere instead of
> > > where it's easiest. If it's relating more to playing diminished
> > > materials on secondary dominants like VI7 or II7, then practice it
> > > there.
>
> > > > I also can't decide on how to practice and think about it, whether I
> > > > think only in terms of half whole, or both half and whole ...
>
> > > It's the same thing as practicing by *always* starting on the b5th.
> > > After awhile that will seem to be predictable and you can move to the
> > > b3rd instead.  The same is true of the diminished scale. Find a
> > > suitable "reflexive" place to put it, get comfortable with it there,
> > > then move to the next difficult location until it loses its difficulty.
>
> > > One more thing: Don't concentrate on this to the exclusion of all other
> > > aspects of music, to show off, or as the only material in your solos.
> > > --
> > > If one plays good music, people don't listen and if one plays bad music
> > > people don't talk.  -- Oscar Wilde
>
> "What hasn't been mentioned is simple vizualization."
>
> Seeing is believing, as it is said. Therefore, believing will only
> enkindle a trusting ear.
>
> Tony,
>
> Your really a theologian "I believe to understand, and understanding
> increases my belief".
>
> I have two ears, ( Old Test. and the New Testament), one mind (
> monotheistic), 3 ways to play the fingerboard, vertical, horizontal, and
> diagonally, ( the Trinity), but when I play I have to have faith in what I
> doing is making music.
>
> Does that work?
>
> Deacon Mark Cleary
> Epiphany Catholic Church

I suppose which ever door anyone wishes to enter ( can be via diverse
standards such as religion and war or even atheism, for a few
examples), the trick is to bind yourself to a fixed course of action,
yet never for a moment assume that there is but one way. Residual
benefits are inevitable. I can attest to that and I am not the only
one. So, yea man, there's where the faith comes into 'play.' Theory
is like a stop sign. Although, it is needed, it stays stationary. The
music moves.

-TD

Gerry

6/18/2012 10:11:00 PM

0

On 2012-06-18 21:43:33 +0000, TD said:

> I suppose which ever door anyone wishes to enter ( can be via diverse
> standards such as religion and war or even atheism, for a few
> examples), the trick is to bind yourself to a fixed course of action,
> yet never for a moment assume that there is but one way. Residual
> benefits are inevitable. I can attest to that and I am not the only
> one. So, yea man, there's where the faith comes into 'play.' Theory
> is like a stop sign. Although, it is needed, it stays stationary. The
> music moves.

I'm reminded of Robert Preston as Professor Harold Hill in Music Man.
All those kids needed was faith--two acts later they're musicians.
Amazing!
--
If one plays good music, people don't listen and if one plays bad music
people don't talk. -- Oscar Wilde

TD

6/18/2012 10:57:00 PM

0

On Jun 18, 6:11 pm, Gerry <addr...@domain.com> wrote:
> On 2012-06-18 21:43:33 +0000, TD said:
>
> > I suppose which ever door anyone wishes to enter ( can be via diverse
> > standards such as religion and war or even atheism, for a few
> > examples), the trick is to bind yourself to a fixed course of action,
> > yet never for a moment assume that there is but one way. Residual
> > benefits are inevitable. I can attest to that and I am not the only
> > one. So, yea man, there's where the faith comes into 'play.'  Theory
> > is like a stop sign. Although, it is needed, it stays stationary. The
> > music moves.
>
> I'm reminded of Robert Preston as Professor Harold Hill in Music Man.
> All those kids needed was faith--two acts later they're musicians.
> Amazing!
> --
> If one plays good music, people don't listen and if one plays bad music
> people don't talk.  -- Oscar Wilde

Did you know that the standard 'Til There Was You, came out of that
musical and the writer made more money on the Beatles cover of it than
from the play or the movie?