There isn't any way to tell from here, operators like << are just names of
methods, so it can be defined however the author of the code wants. What you
need to do is figure out what in_squad returns (p player.in_squad) and then
look up the api for it (if it is a gem, you can do "$ gem server", then open
your web browser to localhost:8808)
···
On Sat, Oct 16, 2010 at 5:23 PM, Paul Roche <prpaulroche@gmail.com> wrote:
Hi, what's the opposite the concatenate sign << ?
For example I want to do the opposite of what the following piece of
code does...........
player.in_squad = player.in_squad << team
This ads a player to the team.
From this syntax, what must I change to take a player from the team?
That is really strange. At first, I simply didn't look closely enough at that, and "fixed" it in my head so that it actually said
team << player.in_squad
Which I would read as "add this player to the team." But your code looks like "add this team to the player" or perhaps "give the player this team on which to be."
So I'm with Josh: in this case, "<<" does NOT mean "concatenate." You'll have to read the docs or the code to figure out what it really does mean, and whether or not any kind of 'opposite' method is available.
Now, if the object on the left were an array, then "<<" means "append," not "concatenate." "Push" also means "append," and the reverse process is "pop."
···
On Oct 16, 2010, at 15:23 , Paul Roche wrote:
Hi, what's the opposite the concatenate sign << ?
For example I want to do the opposite of what the following piece of
code does...........
player.in_squad = player.in_squad << team
This ads a player to the team.
From this syntax, what must I change to take a player from the team?
Yes, we can know this now that you say we are dealing with Strings. It would
not work, for example, with Arrays
name = "John"
lastname = "Smith"
name << lastname # => "JohnSmith"
name.chomp! lastname
name # => "John"
Note that chomp! will return nil in some situations, so don't rely on
assigning from it (if you want to do that, use the non-bang version)
···
On Sat, Oct 16, 2010 at 6:00 PM, Paul Roche <prpaulroche@gmail.com> wrote:
But on a simple level......
say in irb mode I did the following...
name = "John"
name << " Smith"
=> John Smith
Would it be possible to take "John" or "Smith" from name?