Class: ActiveAttr::Typecasting::StringTypecaster

Inherits:
Object
  • Object
show all
Defined in:
lib/active_attr/typecasting/string_typecaster.rb

Overview

Typecasts an Object to a String

Examples:

Usage

StringTypecaster.new.call(1) #=> "1"

Since:

  • 0.5.0

Instance Method Summary collapse

Instance Method Details

#call(value) ⇒ String?

Typecasts an object to a String

Attempts to convert using #to_s.

Examples:

Typecast an Integer

typecaster.call(1) #=> "1"

Parameters:

  • value (Object, #to_s)

    The object to typecast

Returns:

  • (String, nil)

    The result of typecasting

Since:

  • 0.5.0



22
23
24
# File 'lib/active_attr/typecasting/string_typecaster.rb', line 22

def call(value)
  value.to_s if value.respond_to? :to_s
end