Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Validating An Array Argument

DZone's Guide to

Validating An Array Argument

· ·
Free Resource
Source: Chapter 2 - Designing Beautiful APIs [github.com] (O’Reilly’s Ruby Best Practices) via RubyInside.com

 

  
def distance4(*points)
  x1,y1,x2,y2 = points.flatten
  raise ArgumentError unless [x1,y1,x2,y2].all? { |e| Numeric === e }
  Math.hypot(x2 - x1, y2 - y1)
end


 

Resources:
 - Class: Numeric [ruby-doc.org]
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}