Long string arguments

Hello!

I would like to redirect large chunks of text to a specific
resource (file, stderr, etc). I thought that the code below
would do my job:

def |>(s)
myputs %Q|#{s}
end

def <|
>
end

in a similar to eruby fashion, ie:

>>
I don't know much, but I guess
#{42} is a special number.
<|

Unfortunately, I get a syntax error. Any hints?

Regards,

···


University of Athens I bet the human brain
Physics Department is a kludge --Marvin Minsky

Hello!

I would like to redirect large chunks of text to a specific
resource (file, stderr, etc). I thought that the code below
would do my job:

def |>(s)
myputs %Q|#{s}
end

def <|
>
end

Well, that doesn’t work for a number of reasons. For starters it
should basically quote “\nend\n…”. And I don’t think <| and |> are
valid names…

in a similar to eruby fashion, ie:

>>
I don't know much, but I guess
#{42} is a special number.
<|

eRuby basically replace “%>anything<%” with “puts
‘anything’”. Everything else is left as is.

Unfortunately, I get a syntax error. Any hints?

Depends on what you’re trying to do. If you just want chucks of text
in your code:

puts <<EOF
something here…
EOF

If you want eRuby behaviour… Why not just use eRuby? I’ve used it as
templating for emails.

···

On Sat, Mar 13, 2004 at 09:21:27PM +0900, Elias Athanasopoulos wrote:


Thomas
beast@system-tnt.dk

Hi –

Hello!

I would like to redirect large chunks of text to a specific
resource (file, stderr, etc). I thought that the code below
would do my job:

def |>(s)
myputs %Q|#{s}
end

def <|
>
end

Well, that doesn’t work for a number of reasons. For starters it
should basically quote “\nend\n…”. And I don’t think <| and |> are
valid names…

a = Object.new
class << a
define_method(“|>”) {|s| puts s }
end

a.send(“|>”, “a string”) # a string

:slight_smile:

David

···

On Sat, 13 Mar 2004, Thomas Fini Hansen wrote:

On Sat, Mar 13, 2004 at 09:21:27PM +0900, Elias Athanasopoulos wrote:


David A. Black
dblack@wobblini.net

I would like to redirect large chunks of text to a specific
resource (file, stderr, etc). I thought that the code below
would do my job:

def |>(s)
myputs %Q|#{s}
end

def <|
>
end

Well, that doesn’t work for a number of reasons. For starters it
should basically quote “\nend\n…”. And I don’t think <| and |> are
valid names…

Yes. Actually I am aware of why this produces syntax errors. It was
easier to paste it as an idea instead of describing what I was looking
for. :slight_smile:

eRuby basically replace “%>anything<%” with “puts
‘anything’”. Everything else is left as is.

Does something like CPP exist in Ruby? I.e. a way to define some symbols
that expand during the code. In a C-ish way:

#define <% myputs %Q|
#define %> |

Depends on what you’re trying to do. If you just want chucks of text
in your code:

puts <<EOF
something here…
EOF

I produce chunks of text in various places in my program and I like an
interface such as the one eruby uses. Currently, the closest I can get is:

myputs %Q|
            ...
            ...
        >

It would be nice if I could substitute the above with 2 distinct Object’s
operators.

If you want eRuby behaviour… Why not just use eRuby? I’ve used it as
templating for emails.

I don’t want to increase my project’s depedencies.

Regards,

···

On Sat, Mar 13, 2004 at 11:40:54PM +0900, Thomas Fini Hansen wrote:

On Sat, Mar 13, 2004 at 09:21:27PM +0900, Elias Athanasopoulos wrote:

University of Athens I bet the human brain
Physics Department is a kludge --Marvin Minsky

OKOK, they’re valid names, but particular useful names:

irb(main):005:0> a.|> “test”
NameError: undefined method `|’ for #Object:0x40286370

:wink: seems the parser sees > as an operator, which is fair.

···

On Sat, Mar 13, 2004 at 11:53:33PM +0900, David A. Black wrote:

Hi –

On Sat, 13 Mar 2004, Thomas Fini Hansen wrote:

Well, that doesn’t work for a number of reasons. For starters it
should basically quote “\nend\n…”. And I don’t think <| and |> are
valid names…

a = Object.new
class << a
define_method(“|>”) {|s| puts s }
end

a.send(“|>”, “a string”) # a string

:slight_smile:


Thomas
beast@system-tnt.dk

well, why don’t you use ERB then ? it has been included in the core
lib since a long time

···

il Sun, 14 Mar 2004 01:16:09 +0900, Elias Athanasopoulos elathan@phys.uoa.gr ha scritto::

If you want eRuby behaviour… Why not just use eRuby? I’ve used it as
templating for emails.

I don’t want to increase my project’s depedencies.

[snip]

Does something like CPP exist in Ruby? I.e. a way to define some symbols
that expand during the code. In a C-ish way:

#define <% myputs %Q|
#define %> |
[snip]
myputs %Q|


>

It would be nice if I could substitute the above with 2 distinct Object’s
operators.

C/C++ has a preprocessor, Ruby doesn’t.

However using ‘eval’ can easily let you do similar things.

···

On Sun, 14 Mar 2004 01:16:09 +0900, Elias Athanasopoulos wrote:


Simon Strandgaard

“Thomas Fini Hansen” beast@system-tnt.dk schrieb im Newsbeitrag
news:20040313150153.GD24324@saber.xen.dk…

Hi –

Well, that doesn’t work for a number of reasons. For starters it
should basically quote “\nend\n…”. And I don’t think <| and |> are
valid names…

a = Object.new
class << a
define_method(“|>”) {|s| puts s }
end

a.send(“|>”, “a string”) # a string

:slight_smile:

OKOK, they’re valid names, but particular useful names:

irb(main):005:0> a.|> “test”
NameError: undefined method `|’ for #Object:0x40286370

:wink: seems the parser sees > as an operator, which is fair.

In fact there are two operators, namely “|” and “>”. And expr “|” “>” is
not valid Ruby syntax.

You can do things like

puts <<EOM
This
is
a
multi
line
String
that
can
get
quite
long
and
even
contain
expressions
like
#{1+2}.
EOM

puts %{
This
is
double
quote
text.
\tsee?
#{1+2}
}

%Q{} works also, as well as “”.

puts %q{
This
is
single
quote
text.
\tsee?
#{1+2}
}

robert
···

On Sat, Mar 13, 2004 at 11:53:33PM +0900, David A. Black wrote:

On Sat, 13 Mar 2004, Thomas Fini Hansen wrote: