Data update
This commit is contained in:
parent
81fd053722
commit
52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions
27
Task/Call-an-object-method/Elixir/call-an-object-method.ex
Normal file
27
Task/Call-an-object-method/Elixir/call-an-object-method.ex
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
defmodule ObjectCall do
|
||||
def new() do
|
||||
spawn_link(fn -> loop end)
|
||||
end
|
||||
|
||||
defp loop do
|
||||
receive do
|
||||
{:concat, {caller, [str1, str2]}} ->
|
||||
result = str1 <> str2
|
||||
send caller, {:ok, result}
|
||||
loop
|
||||
end
|
||||
end
|
||||
|
||||
def concat(obj, str1, str2) do
|
||||
send obj, {:concat, {self(), [str1, str2]}}
|
||||
|
||||
receive do
|
||||
{:ok, result} ->
|
||||
result
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
obj = ObjectCall.new()
|
||||
|
||||
IO.puts(obj |> ObjectCall.concat("Hello ", "World!"))
|
||||
Loading…
Add table
Add a link
Reference in a new issue