Skip to content

Instantly share code, notes, and snippets.

@BrooklinJazz
Created June 7, 2021 18:04
Show Gist options
  • Select an option

  • Save BrooklinJazz/bbd545ffebcfeb4aff64d9f441ddccc6 to your computer and use it in GitHub Desktop.

Select an option

Save BrooklinJazz/bbd545ffebcfeb4aff64d9f441ddccc6 to your computer and use it in GitHub Desktop.
Demonstrate elixir functions with different parameters
defmodule Greeting do
def say_hello do
"Hello"
end
def say_hello(name) do
"Hello #{name}"
end
def say_hello(name1, name2) do
"Hello #{name1}, Hi #{name2}"
end
end
IO.puts Greeting.say_hello() # Hello
IO.puts Greeting.say_hello("Bob") # Hello Bob
IO.puts Greeting.say_hello("Bob", "Bill") # Hello Bob, Hi Bill
IO.puts Greeting.say_hello("Bob", "Bill", "Billy")
# (UndefinedFunctionError) function Greeting.say_hello/3 is undefined or private. Did you mean one of:
* say_hello/0
* say_hello/1
* say_hello/2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment