Over a million developers have joined DZone.

Validating An Array Argument

·
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:

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

{{ parent.tldr }}

{{ parent.urlSource.name }}