please help. what does mean <<

  • Thread starter Kalinkin Kirill
  • Start date
K

Kalinkin Kirill

I have to translate code from ruby to .net
And I dont understand what means << in the code. Its simple I know but
please do not delete question and answer the question please

def eval_op(op, val1, val2, expr1, expr2, source, source_expr)
result = val1.send(op, val2)
expr = "(#{expr1} #{op} #{expr2})"
test(result, expr)
source << result; source_expr << expr
find(source, source_expr)
source.pop; source_expr.pop
end

Thanks in advance!
 
R

Rick DeNatale

I have to translate code from ruby to .net
And I dont understand what means << in the code. Its simple I know but
please do not delete question and answer the question please

def eval_op(op, val1, val2, expr1, expr2, source, source_expr)
=A0result =3D val1.send(op, val2)
=A0expr =3D "(#{expr1} #{op} #{expr2})"
=A0test(result, expr)
=A0source << result; source_expr << expr
=A0find(source, source_expr)
=A0source.pop; source_expr.pop
end

Thanks in advance!

It depends on what objects source and source_expr are.

<< is just a message, and different objects can implement it differently.

For integers << x means shift left x bits,

For arrays << x means append x to the end of the array.

Most classes will implement << with something like one of these two
meanings in mind.

There's no way to tell from that snippet of code whether source and
source_expr are instances of standard Ruby classes or classes written
as part of the overall application.


--=20
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
 
M

Mister Freeman

Rick said:
It depends on what objects source and source_expr are.

<< is just a message, and different objects can implement it
differently.

For integers << x means shift left x bits,

For arrays << x means append x to the end of the array.

It is an array and it means that the operation is push. Thanks a lot for
the quick answer! I became fan of ruby. So elegant language!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top