File: source.md

package info (click to toggle)
ruby-faker 2.21.0-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,076 kB
  • sloc: ruby: 19,088; makefile: 6
file content (25 lines) | stat: -rw-r--r-- 719 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Faker::Source
Need to generate a code sample for something? Just give me the language (defaults to `ruby`, obviously).

```ruby
# Keyword arguments: lang
Faker::Source.hello_world #=> "print 'Hello World!'"
Faker::Source.hello_world(lang: :javascript) #=> "alert('Hello World!');"

# Keyword arguments: str, lang
Faker::Source.print #=> "print 'some string'"
Faker::Source.print(str: 'cake') #=> "print 'cake'"
Faker::Source.print(str: 'cake', lang: :javascript) #=> "console.log('cake');"

# Keyword arguments: lang
Faker::Source.print_1_to_10 <<-DOC=> "
  10.times do |i|
    print i
  end"
DOC
Faker::Source.print_1_to_10(lang: :javascript) <<-DOC=> "
  for (let i=0; i<10; i++) {
    console.log(i);
  }"
DOC
```