@@ -61,8 +61,14 @@ defmodule IEx.Helpers do
61
61
c "baz.ex"
62
62
#=> [Baz]
63
63
"""
64
- def c ( files , path // "." ) do
65
- { erls , exs } = Enum . partition ( List . wrap ( files ) , & String . ends_with? ( & 1 , ".erl" ) )
64
+ def c ( files , path // "." ) when is_binary ( path ) do
65
+ files = List . wrap ( files )
66
+
67
+ unless Enum . all? ( files , & is_binary / 1 ) do
68
+ raise ArgumentError , message: "expected a binary or a list of binaries as argument"
69
+ end
70
+
71
+ { erls , exs } = Enum . partition ( files , & String . ends_with? ( & 1 , ".erl" ) )
66
72
67
73
modules = Enum . map ( erls , fn ( source ) ->
68
74
{ module , binary } = compile_erlang ( source )
@@ -82,8 +88,8 @@ defmodule IEx.Helpers do
82
88
end
83
89
84
90
@ doc """
85
- Prints the list of all loaded modules with paths to their corresponding .beam
86
- files.
91
+ Prints the list of all loaded modules with paths to
92
+ their corresponding `.beam` files.
87
93
"""
88
94
def m do
89
95
all = Enum . map :code . all_loaded , fn { mod , file } -> { inspect ( mod ) , file } end
@@ -283,7 +289,7 @@ defmodule IEx.Helpers do
283
289
Please note that all the modules defined in the same file as `module`
284
290
are recompiled and reloaded.
285
291
"""
286
- def r ( module ) do
292
+ def r ( module ) when is_atom ( module ) do
287
293
case do_r ( module ) do
288
294
mods when is_list ( mods ) -> { module , mods }
289
295
other -> other
@@ -308,7 +314,7 @@ defmodule IEx.Helpers do
308
314
Load the given module's beam code (and ensures any previous
309
315
old version was properly purged before).
310
316
"""
311
- def l ( module ) do
317
+ def l ( module ) when is_atom ( module ) do
312
318
:code . purge ( module )
313
319
:code . load_file ( module )
314
320
end
@@ -350,7 +356,7 @@ defmodule IEx.Helpers do
350
356
@ doc """
351
357
Changes the current working directory to the given path.
352
358
"""
353
- def cd ( directory ) do
359
+ def cd ( directory ) when is_binary ( directory ) do
354
360
case File . cd ( expand_home ( directory ) ) do
355
361
:ok -> pwd
356
362
{ :error , :enoent } ->
@@ -362,7 +368,7 @@ defmodule IEx.Helpers do
362
368
Produces a simple list of a directory's contents.
363
369
If `path` points to a file, prints its full path.
364
370
"""
365
- def ls ( path // "." ) do
371
+ def ls ( path // "." ) when is_binary ( path ) do
366
372
path = expand_home ( path )
367
373
case File . ls ( path ) do
368
374
{ :ok , items } ->
0 commit comments