OptionValue[name]OptionsPattern.OptionValue[f, name]OptionValue[f, opts, name]OptionValue[..., list]First, set up a symbol with some options using Options:
Options[MySetting] = {"foo" -> 5, "bar" -> 6}
Now get a value previously set:
OptionValue[MySetting, "bar"]
If the option does exist we get a message:
OptionValue[MySetting, "baz"]
Use OptionValue to get the value of option a inside OptionsPattern a->3
f[a->3] /. f[OptionsPattern[{}]] -> {OptionValue[a]}
An unavailable option returns argument and does not generate a message:
f[a->3] /. f[OptionsPattern[{}]] -> {OptionValue[b]}
The argument of OptionValue must be a symbol:
f[a->3] /. f[OptionsPattern[{}]] -> {OptionValue[a+b]}
However, the symbol can be evaluated dynamically:
f[a->5] /. f[OptionsPattern[{}]] -> {OptionValue[Symbol["a"]]}
See also Options and OptionsPattern.