Method: Faker::Types.random_type

Defined in:
lib/faker/default/types.rb

.random_typeString, Integer

Produces a random type that’s either a String or an Integer.

Examples:

Faker::Types.random_type #=> 1 or "a" or "bob"

Returns:

  • (String, Integer)

Available since:

  • 1.8.6



118
119
120
121
122
123
124
125
126
# File 'lib/faker/default/types.rb', line 118

def random_type
  type_to_use = SIMPLE_TYPES[rand(0..SIMPLE_TYPES.length - 1)]
  case type_to_use
  when :string
    rb_string
  when :fixnum
    rb_integer
  end
end