Class: Faker::Source

Inherits:
Base
  • Object
show all
Defined in:
lib/faker/default/source.rb

Constant Summary

Constants inherited from Base

Base::LLetters, Base::Letters, Base::NOT_GIVEN, Base::Numbers, Base::ULetters

Class Method Summary collapse

Methods inherited from Base

bothify, disable_enforce_available_locales, fetch, fetch_all, flexible, generate, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, resolve, respond_to_missing?, sample, shuffle, translate, unique, with_locale

Class Method Details

.hello_world(lang: :ruby) ⇒ String

Produces source code for Hello World in a given language.

Examples:

Faker::Source.hello_world #=> "puts 'Hello World!'"
Faker::Source.hello_world(lang: :javascript)
  #=> "alert('Hello World!');"

Parameters:

  • lang (Symbol) (defaults to: :ruby)

    The programming language to use

Returns:



20
21
22
# File 'lib/faker/default/source.rb', line 20

def hello_world(lang: :ruby)
  fetch("source.hello_world.#{lang}")
end

Produces source code for printing a string in a given language.

Examples:

Faker::Source.print #=> "puts 'faker_string_to_print'"
Faker::Source.print(str: 'foo bar', lang: :javascript)
  #=> "console.log('foo bar');"

Parameters:

  • str (String) (defaults to: 'some string')

    The string to print

  • lang (Symbol) (defaults to: :ruby)

    The programming language to use

Returns:



38
39
40
41
# File 'lib/faker/default/source.rb', line 38

def print(str: 'some string', lang: :ruby)
  code = fetch("source.print.#{lang}")
  code.gsub('faker_string_to_print', str)
end

Produces source code for printing 1 through 10 in a given language.

Examples:

Faker::Source.print_1_to_10 #=> "(1..10).each { |i| puts i }"
Faker::Source.print_1_to_10(lang: :javascript)
# => "for (let i=0; i<10; i++) {
#       console.log(i);
#    }"

Parameters:

  • lang (Symbol) (defaults to: :ruby)

    The programming language to use

Returns:



58
59
60
# File 'lib/faker/default/source.rb', line 58

def print_1_to_10(lang: :ruby)
  fetch("source.print_1_to_10.#{lang}")
end