# FactoryGirl Sequences

[FactoryGirl sequences](https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md#sequences) are often used inline for unique values such as emails:

```ruby
factory :user do
  sequence(:email) { |n| "person#{n}@example.com" }
end
```

However, a sequence can be defined on its own

```ruby
FactoryGirl.define do
  sequence :email do |n|
    "person#{n}@example.com"
  end
end
```

That means it can be invoked outside the context of a factory

```ruby
> FactoryGirl.generate :email
=> "person1@example.com"
> FactoryGirl.generate :email
=> "person2@example.com"
```

Or it can be used as a shared sequence across multiple factories

```ruby
factory :customer do
  ...
  email
end

factory :admin do
  ...
  email
end
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ploegert.gitbook.io/til/programmy/ruby/factory-girl-sequences.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
